print("Entre nummber 1: ")
num1 = float(input('> '))
print("Entre opperation: ")
op = input('> ')
print("Entre nummber 2: ")
num2 = float(input('> '))
result = print("Your Result is:")
if op == "+":
print(num1 + num2)
print(result)
print("Done")
elif op == '-':
print(num1 - num2)
print(result)
print("Done")
elif op == '/':
print(num1 / num2)
print(result)
print("Done")
elif op == '*':
print(num1 * num2)
print(result)
print("Done")
elif op == '**':
print(num1 ** num2)
print(result)
print("Done")
else:
print("Entre a valid opperation")
我试图做一个计算器。它工作正常,但最后没有明显原因弹出“ none”。
我不知道为什么。任何帮助表示赞赏。
result = print("Your Result is:")
print("Your Result is:")
打印此字符串"Your Result is:"
并返回None
,现在result
等于None
。然后print(result)
打印None
result = print("Your Result is:")
print
不返回任何内容None
结果值为None
print(result) #this is none
您应该将其存储在类似的变量中
result = num1 + num2
print(result) #with calculated value
# remove result = print("Your result is :")
# Add this result = num1 'operation +/-/*/** etc' num2 after your if condittions.
# for example :
if op == "+":
result = num1 + num2
print("Your result is :",result)
if op == "-" :
result = num1 - num2
print("Your result is :",result)
# It will work fine.