如何在PYTHON里用IF和INPUT制作计算器

时间:2024-10-12 17:37:25

1、打开JUPYTER NOTEBOOK,新建一个PYTHON文档。

如何在PYTHON里用IF和INPUT制作计算器

3、number_1 = input("Please input the first number: ")number_2 = input("Please input the second number: ")caculation = input("Please enter operator: ")算法我们也要提示用户输入。

如何在PYTHON里用IF和INPUT制作计算器

5、number_1 = float(input("Please input the first number: "))number_2 = float(input("Please input the second number: "))caculation = input("Please enter operator: ")if caculation == "+": print(number_1 + number_2)elif caculation == "-": print(number_1 - number_2)elif caculation == "*": print(number_1 * number_2)elif caculation == "/": print(number_1 / number_2)用IF和ELIF来排除条件。

如何在PYTHON里用IF和INPUT制作计算器

7、number_1 = float(input("Please input the first number: "))number_2 = float(input("Please input the second number: "))caculation = input("Please enter operator: ")if caculation == "+": print(number_1 + number_2)elif caculation == "-": print(number_1 - number_2)elif caculation == "*": print(number_1 * number_2)elif caculation == "/": print(number_1 / number_2)else: print("wrong type")尝试一下一些复杂的数值来测试是否制作完成。

如何在PYTHON里用IF和INPUT制作计算器
© 2025 长短途
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com