import math
deftemperture_convertion():
celsius =eval(input("输入摄氏温度:"))
fahrenheit =(9/5)*celsius+32print("华氏温度为:",fahrenheit)
计算圆柱体的面积
defcalculate_the_area_of_cylinder():
radius,length =eval(input("Enter the radius and length of a culinder:"))
area = radius * radius * math.pi
volume = area * length
print("The area is %.2f"%area)print("The volume is %.2f"%volume)
对一个整数中的各位数字求和
defsummation():
number =eval(input("输入一个1-1000之间的整数:"))
single_digits = number %10
ten_digits = number //10%10
percentile = number //100sum= single_digits + ten_digits + percentile
print("The sum of the digits is %d"%sum)
计算年数和天数
defnumber_of_year_and_days():
input_minutes =eval(input("Enter the number of minutes:"))
days = input_minutes//(60*24)%365
years = input_minutes//(60*24)//365print("%d minutes is approcimately %d years and %d days"%(input_minutes,years,days))
计算能量
defcalculate_power():
amount_of_water =eval(input("Enter the amount of water in kilograms:"))
initial_temputure =eval(input("Enter the initial temputure:"))
final_temputure =eval(input("Enter the final tempure:"))
Q = amount_of_water *(final_temputure - initial_temputure)*4184print("The energy needed is %.1f"%Q)
金融应用程序
defcalculate_investment():
account =eval(input("Enter the account value:"))
interest_rate =eval(input("Enter annual interest rate in percent:"))
number_of_years =eval(input("Enter the number of years:"))
initial_deposit = account/(1+interest_rate/100)**(number_of_years*12)print("Initial deposit value is %f"%initial_deposit)
提示用户输入四位数并反向显示
defreverse_display_figures():
num =str(input("Enter an integer:"))for i inrange(len(num)):print(num[-(i+1)],end="\n")
import time
defshow_current_time():
time_zone =eval(input("Enter the time zone:"))
current_time = time.time()# 获取当前时间
total_senconds =int(current_time)
current_sencond = total_senconds %60
total_minutes = total_senconds //60
current_minute = total_minutes %60
total_hours = total_minutes //60
current_hour = total_hours %24
china_curent_hour = current_hour + time_zone
print("current time is ", china_curent_hour,':',current_minute,":",
current_sencond,'China')
计算未来投资额
deffuture_investment():
investment_amount =eval(input("Enter investment amount:"))
annual_interest_rate =eval(input("Enter annual interest rate:"))
year =eval(input("Enter number of years:"))
accumulated_value = investment_amount*(1+annual_interest_rate/100)**year
print("Accumulated value is %f"%accumulated_value)
金融应用程序 复利值
defcompound_interest():
saving_amount =eval(input("Enter the monthly saving amount:"))
month_interest =0.00417
month =eval(input("Enter the month:"))
saving_amount_profit = saving_amount*(1+month_interest)for i inrange(month-1):
saving_amount_profit =(saving_amount+saving_amount_profit)*(1+month_interest)
人口预测
defprojected_population():
year =eval(input("Enter the number of years:"))
population =3120324986
people_born_every_second =7
people_dead_every_second =13
new_immigration =45
the_time_of_every_year =365*24*60*60* year
annual_population_bored_increase = the_time_of_every_year // people_born_every_second
annual_population_immigration = the_time_of_every_year // new_immigration
annual_population_dead = the_time_of_every_year // people_dead_every_second
annual_population_increase = population + annual_population_bored_increase + annual_population_immigration - annual_population_dead
the_total_of_5_years_population = annual_population_increase
print("%d年后的总人口为:%d"%(year,the_total_of_5_years_population))if __name__ =='__main__':
projected_population()