这是代码,
while True :
print(" your options are ")
print(" enter add to add numbers ")
print(" enter sub to subtract two numbers ")
user_input = input("")
if user_input == "quit":
break
elif user_input == "add":
print ("you entered" +user_input )
num1 = float (input ("enter a number"))
num2 = float (input ("enter second number"))
res = str ( num1 + num2 )
print ( "result is" +res)
elif user_input == "sub":
print (user_input)
num3 = float (input ("enter a number"))
num4 = float (input ("enter second number"))
res1 = str ( num3 + num4 )
print ( "result is" +res4)
并输入:
add
1
1
这是输出
your options are
enter add to add numbers
enter sub to subtract two numbers
you enteredadd
enter a number enter second number result
is2.0
your options are
enter add to add numbers
enter sub to subtract two numbers
Traceback (most recent call last):
File "..\Playground", line 5, in
<module>
user input = input("")
EOFError: EoF when reading a line
是的,在计算了加法之后,可打印的文本已经重复了。