Files
Python-Programming-Exercise/20210720-第2章.py
2025-09-25 21:23:34 +08:00

102 lines
4.2 KiB
Python

# ==============================================================================
# 通过 D:\文档\电子文档\个人\脚本库\PythonScript\第2章.py + 题号 运行
# 程序名:
# 第2章习题
# 目的:
#
# 修订记录:
# 日期 编程者 改动描述
# =================== ============= =====================================
# 2021-07-20 21:29:18 Sola 2-1 介绍呗
# 2021-07-20 21:29:30 Sola 2-2 介绍完不自动退出
# 2021-07-20 21:29:42 Sola 2-3 计算平均分
# 2021-07-20 21:29:54 Sola 2-4 计算5次华氏度
# 2021-07-20 21:30:22 Sola 2-5 计算0~100℃对应华氏度
# 2021-07-20 21:30:47 Sola 2-6 本金利滚利
# 2021-07-20 21:31:11 Sola 2-7 追加利滚利
# 2021-07-20 21:31:21 Sola 2-8 利滚利滚利(我是有极限的!)
# 2021-07-20 21:35:18 Sola 2-9 华氏度转摄氏度
# 2021-07-20 21:38:07 Sola 2-10 千米转英里
# 2021-07-20 21:42:45 Sola 2-11 任意一个单位转换 略
# 2021-07-20 21:42:59 Sola 2-12 Python计算器
def test2_1():
print("Hello, World! 这里我就懒得再改介绍了,怪麻烦的。")
def test2_2():
print("Hello, World! 这里我就懒得再改介绍了,怪麻烦的。")
input("Press the <Enter> key to quit.")
def test2_3():
print("This program computes the average of two exam scores.")
score1, score2, score3 = eval(input("Enter three scores separated by a comma: "))
average = (score1 + score2 + score3) / 3
print("The average of the scores is:", average)
def test2_4():
for i in range(5):
celsius = eval(input("What is the Celsius temperature? "))
fahrenheit = 9/5 * celsius + 32
print("The temperature is", fahrenheit, "degrees Fahrenheit.")
def test2_5():
celsius = 0
print("摄氏度(℃)\t华氏度(℉)")
for i in range(11):
fahrenheit = 9/5 * celsius + 32
print('', celsius, "\t\t", fahrenheit)
celsius = celsius + 10
def test2_6():
print("This program calculates the future value of a investment.")
principal = eval(input("Enter the initial principal: "))
years = eval(input("Enter the number of years of your investment: "))
apr = eval(input("Enter the annual interest rate: "))
for i in range(years):
principal = principal * (1 + apr)
print("The value in", years, "years is:", principal)
def test2_7():
print("This program calculates the future value of a investment.")
investment = eval(input("Enter the annual investment: "))
years = eval(input("Enter the number of years of your investment: "))
apr = eval(input("Enter the annual interest rate: "))
principal = investment
for i in range(years):
principal = principal * (1 + apr) + investment
print("The value in", years, "years is:", principal)
def test2_8():
print("This program calculates the future value of a investment.")
principal = eval(input("Enter the initial principal: "))
years = eval(input("Enter the number of years of your investment: "))
times = eval(input("Enter the number of interest calculations per year: "))
apr = eval(input("Enter the annual interest rate: "))
for i in range(years):
for j in range(times):
principal = principal * (1 + apr / times)
print("The value in", years, "years is:", principal)
def test2_9():
fahrenheit = eval(input("What is the Fahrenheit temperature? "))
celsius = 5/9 * ( fahrenheit - 32 )
print("The temperature is", celsius, "degrees celsius.")
def test2_10():
km = eval(input("请输入千米数: "))
print(km, "km =", 0.62 * km, "mile")
def test2_11():
print("太简单,略过,,,实在懒得再重写一个了")
def test2_12():
print("Python 交互式科学计算器")
for i in range(100):
expr = input("请输入算数表达式:")
a = eval(expr)
print(expr, "的结果为", a, ",您还可以计算", 99 - i, "")
import sys
def run(num):
eval("test2_" + num + "()")
run(sys.argv[1])