''none'无明显理由打印

问题描述 投票:2回答:3
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

python python-3.7
3个回答
4
投票
result = print("Your Result is:")

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


2
投票
result = print("Your Result is:")

print不返回任何内容None

结果值为None

print(result) #this is none

您应该将其存储在类似的变量中

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

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. 
© www.soinside.com 2019 - 2024. All rights reserved.