个人简历网页模板

admin 636 0

以下是一个简单的编程案例,用Python语言编写一个计算器程序:

```python

# 计算器程序

def add(x, y):

"""相加"""

return x + y

def subtract(x, y):

"""相减"""

return x - y

def multiply(x, y):

"""相乘"""

return x * y

def divide(x, y):

"""相除"""

if y == 0:

raise ValueError("除数不能为0")

return x / y

# 用户输入

num1 = float(input("请输入第一个数字: "))

num2 = float(input("请输入第二个数字: "))

print("请选择操作:")

print("1. 相加")

print("2. 相减")

print("3. 相乘")

print("4. 相除")

choice = input("请输入您的选择(1/2/3/4): ")

if choice == '1':

print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2':

print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3':

print(num1, "*", num2, "=", multiply(num1, num2))

elif choice == '4':

print(num1, "/", num2, "=", divide(num1, num2))

else:

print("非法输入")

```