python简单例题(python的简单联系题)

1年前 (2023-09-07)阅读103回复0
郝甜甜
郝甜甜
  • 注册排名10011
  • 经验值0
  • 级别
  • 主题0
  • 回复0
楼主

Python 是一种通用高级编程语言,可用于开发各种应用程序。下面是一个简单的 Python 练习题:

print("Enter two numbers: ")
num1 = int(input())
num2 = int(input())
print("Select an operation (+, -, *, /): ")
oper = input()
if oper == '+':
print(num1, "+", num2, "=", num1 + num2)
elif oper == '-':
print(num1, "-", num2, "=", num1 - num2)
elif oper == '*':
print(num1, "*", num2, "=", num1 * num2)
elif oper == '/':
if num2 == 0:
print("Error: Denominator cannot be zero.")
else:
print(num1, "/", num2, "=", num1 / num2)
else:
print("Error: Invalid operator.")

这个程序提示用户输入两个数并选择操作符。然后,利用简单的 if…elif…else 逻辑来计算结果。

通过这个练习,你可以学习如何使用 Python 的输入、输出、变量和控制流语句。

本文可能转载于网络公开资源,如果侵犯您的权益,请联系我们删除。

本文地址:https://www.pyask.cn/info/183.html

0
回帖

python简单例题(python的简单联系题) 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息