没有明显原因的“无”打印

时间:2019-10-19 12:39:33

标签: python python-3.7

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”。

我不知道为什么。任何帮助表示赞赏。

这是问题所在: enter image description here

3 个答案:

答案 0 :(得分:4)

result = print("Your Result is:")

print("Your Result is:")打印此字符串"Your Result is:"并返回None,现在result等于None。然后print(result)打印None

答案 1 :(得分:2)

result = print("Your Result is:")

print不返回None

结果值为None

print(result) #this is none

您应该将其存储在变量中,例如

result = num1 + num2
print(result) #with calculated value

答案 2 :(得分:0)

# 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.