简体   繁体   English

'none' 无明显原因打印

[英]'none' prints for no apparent reason

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")

I tried to make a calculator.我试着做一个计算器。 It works fine but when at the end a 'none' pops up for no apparent reason.它工作正常,但是当最后没有明显原因弹出“无”时。

I don't know why.我不知道为什么。 Any help is appreciated.任何帮助表示赞赏。

This is the problem:这就是问题: 在此处输入图像描述

result = print("Your Result is:")

print("Your Result is:") prints this string "Your Result is:" and returns None and now result is equal None . print("Your Result is:")打印此字符串"Your Result is:"并返回None ,现在result等于None then print(result) prints None然后print(result)打印None

result = print("Your Result is:")

print return nothing None print什么都不返回None

value of result is None结果的值为None

print(result) #this is none

You should store it in a variable like你应该把它存储在一个变量中,比如

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. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM