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
print("Your Result is:")
"Your Result is:"
None
result
print(result)
print ничего не вернуть None
print
значение результата равно 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.