一、输出打印姓名、学号(以Python为例)
Python
1name = "张三"
2student_id = "20200001"
3print("姓名:", name)
4print("学号:", student_id)
二、提取身份证号码中的出生年份和月份(以Python为例)
假设身份证号码存储在变量id_number
中,且为18位标准格式。
Python
1def extract_birth_info(id_number):
2 year = int(id_number[6:10]) # 提取年份
3 month = int(id_number[10:12]) # 提取月份
4 return year, month
5
6id_number = "320101199001012345"
7birth_year, birth_month = extract_birth_info(id_number)
8print(f"出生年份:{birth_year}年")
9print(f"出生月份:{birth_month}月")
三、计算基本算术操作
Python
1print("100 + 10 =", 100 + 10)
2print("100 - 10 =", 100 - 10)
3print("100 * 10 =", 100 * 10)
4print("100 / 10 =", 100 / 10)
四、条件判断返回字符串
Python
1x = 100
2y = 50
3if x > y:
4 print("回答正确,你太棒啦")
5else:
6 print("回答错误,下次仔细点")
五、计算复利本利和
Python
1principal = 100000 # 本金
2annual_rate = 0.05 # 年利率
3years = 3 # 年限
4
5final_amount = principal * (1 + annual_rate) ** years
6print(f"三年后,本利和为:{final_amount:.2f}元")
六、统计手机号码中的数字(以Python为例)
对于统计手机号码中的数字,实际上问题表述可能有误,因为一般统计手机号码中的数字并没有特别的计算需求,通常只是展示或验证格式。如果目的是验证手机号码格式,可以这样做:
1phone_number = "13812348888"
2
3# 简单验证手机号码格式是否符合常见规则(非严格校验,仅作示例)
4if len(phone_number) == 11 and phone_number.startswith(("13", "14", "15", "16", "17", "18", "19")):
5 print("手机号码格式正确")
6else:
7 print("手机号码格式不正确")
七、分析好生意有限责任公司经营成果
Python
1def analyze_financial_results(year, revenue, costs):
2 """分析并输出公司经营成果"""
3 if revenue > costs:
4 result = "盈利"
5 else:
6 result = "亏损"
7 print(f"{year}年度的经营成果是:{result}")
8
9# 2022年度
10analyze_financial_results(2022, 10000000, 8000000)
11
12# 2023年度
13analyze_financial_results(2023, 15000000, 16000000)
八、输出0至100的所有偶数
Python
1for number in range(0, 101, 2):
2 print(number, end=" ")
九、输出0至100的所有奇数
Python
1for number in range(1, 101, 2):
2 print(number, end=" ")
十题
def calculate_tax(income):tax_rates = [(36000, 3, 0),(108000, 10, 2520),(156000, 20, 16920),(120000, 25, 31920),(240000, 30, 52920),(300000, 35, 85920)]taxable_income = incometax = 0for bracket, rate, deduction in tax_rates:if taxable_income <= 0:breakif taxable_income > bracket:tax += (bracket * rate / 100) - deductiontaxable_income -= bracketelse:tax += (taxable_income * rate / 100) - deductiontaxable_income = 0return tax# 测试代码
incomes = {"小王": 120000, "小刘": 280000, "小张": 550000, "小陈": 860000}
for person, income in incomes.items():tax = calculate_tax(income)print(f"{person}的应纳税所得额为{income}元,本年应纳税额为{tax:.2f}元。")