运行此代码时,我遇到了第二个 def 的问题,* de *f multiply (): 当我收到语法错误时,def 的 de 被剔除。
import random
def start () :
print "Welcome!"
choose ()
def choose () :
choice = input """would you like to
add, subtract, or multiply?
1 2 3
"""
if choice = 1 :
add ()
if choice = 2 :
subtract ()
if choice = 3 :
multiply ()
def multiply () :
x = random.random ()
x = round ()
y = random.random ()
y = round ()
print "What is the answer to: ", x,"*", y, " ?"
answer = input ": "
z = x*y
if answer == z :
print "you are correct!"
elif answer < z :
print "your answer is low! The correct answer was ", z
elif answer > z :
print "your answer is high! The correct answer was ", z
multiply ()
def add () :
x = random.random ()
x = round ()
y = random.random ()
y = round ()
print "What is the answer to: ", x,"+", y, " ?"
answer = input ": "
z = x+y
if answer == z :
print "you are correct!"
elif answer < z :
print "your answer is low! The correct answer was ", z
elif answer > z :
print "your answer is high! The correct answer was ", z
def subtract () :
x = random.random ()
x = round ()
y = random.random ()
y = round ()
print "What is the answer to: ", x,"*", y, " ?"
answer = input ": "
z = x*y
if answer == z :
print "you are correct!"
elif answer < z :
print "your answer is low! The correct answer was ", z
elif answer > z :
print "your answer is high! The correct answer was ", z