[英]'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")
我試着做一個計算器。 它工作正常,但是當最后沒有明顯原因彈出“無”時。
我不知道為什么。 任何幫助表示贊賞。
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.