请帮助,因为我是一个真正的初学者,很想了解更多。我正在尝试了解有关循环的更多信息,因此请查看此代码。
# lets the user input first number
num1 = float(raw_input("Enter your first number ---> "))
# lets the user input second number
num2 = float(raw_input("Enter your second number ---> "))
#the next four lines sets the basic mathematical equations
addAns = num1+num2
subAns = num1-num2
mulAns = num1*num2
divAns = num1/num2
# ask the user to let the program know what equation to run with an
option of running them all
operator = raw_input("What operator would you like to use(+,-,*,/ or ALL)")
#these if and else statements are based on the input by the user.
Depending on the operator chosen it will print that equation.
if operator == "+":
print "the result of:\t " ,num1, "+" ,num2, "=" ,addAns,
elif operator == "-":
print "\nthe result of:\t " ,num1, "-" ,num2, "=" ,subAns,
elif operator == "*":
print "\nthe result of:\t " ,num1, "*" ,num2, "=" ,mulAns,
elif operator == "/":
print "\nthe result of:\t " ,num1, "/" ,num2, "=" ,divAns,
elif operator == "ALL" or "all" or "All":
print "the result of:\t " ,num1, "+" ,num2, "=" ,addAns,
print "\nthe result of:\t " ,num1, "-" ,num2, "=" ,subAns,
print "\nthe result of:\t " ,num1, "*" ,num2, "=" ,mulAns,
print "\nthe result of:\t " ,num1, "/" ,num2, "=" ,divAns,
问题是如果我要让用户告诉我是或否,我如何让这个程序重新开始,例如:
answer = raw_input("Would you like to try again?(yes or no)")
if answer = "yes"
then restart?????
else answer = "no"
print "Thanks for using my calculator!!!"