为什么我的答案没有打印出来? [英] Why is my answer not printed ?
问题描述
打印(选择你想要执行的操作:)
print(1 for add)
print(2 for subtract)
print(3 for multiply)
print(4 for divide)
choice = input(选择你想要的操作号码)
x = int(输入(操作的第一个数字))
n = int(输入(操作的第二个数字))
如果选择== 1:
print(int(x)+ int(n))
如果选择== 2:
print(x - n)
如果选择== 3:
print(x * n)
如果选择== 4:
打印(x / n)
我的尝试:
我试过制作一种小型的计算器。但它不打印答案
我用Google搜索了它并且还问了我的一群朋友,但是没有人能够解决我的查询
< blockquote>你的选择
变量是字符串类型,但你要将它与整数文字进行比较。
所以要么make它是一个int:
choice = int(输入( 选择您想要操作的数字))
或执行字符串比较:
if choice == 1:
print("select the operation you want to perform :")
print(" 1 for add")
print(" 2 for subtract")
print(" 3 for multiply")
print(" 4 for divide")
choice = input("select the number you want for operation")
x = int(input("first number for operation"))
n = int(input("second number for operation"))
if choice == 1:
print(int(x) + int(n))
if choice == 2:
print(x - n )
if choice == 3:
print(x * n)
if choice == 4:
print(x / n)
What I have tried:
I have tried to make a small type of calculator . but it is not printing the answer
I have googled it and also asked my bunch of friends but no one is able to solve my query
Yourchoice
variable is of type string but you are comparing it with integer literals.
So either make it an int:
choice = int(input("select the number you want for operation"))or perform string comparisons:
if choice == "1":
这篇关于为什么我的答案没有打印出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!