首页 技术 正文
技术 2022年11月20日
0 收藏 392 点赞 3,899 浏览 1612 个字

2.1

《python语言程序设计》_第二章编程题

程序:

Celsius=eval(input(“Enter a degree in Celsius:”))
#输入摄氏度的值Celsius
fahrenheit =(9/5)*Celsius + 32
#定义华氏温度fahrenheit
print(Celsius,”Celsius is”,fahrenheit,”Fahrenheit”)

结果:

Enter a degree in Celsius:43
43 Celsius is 109.4 Fahrenheit

《python语言程序设计》_第二章编程题

2.2 读取半径和高来计算圆柱体底面面积和体积

设计:

area = radius * radius *∏

volume =area * length

程序:

radius,length = eval (input(“Enter the radius and length of cylinder:” ))
#输入半径radius和高length
area = radius*radius*3.14
#定义面积公式
volume = area * length
#定义圆柱体的体积
print(“The area is”,area)
print(“The volume is”,volume)

结果:

Enter the radius and length of cylinder:5.5,12
The area is 94.985
The volume is 1139.82

《python语言程序设计》_第二章编程题

2.3 英尺转米尺,一英尺等于0.305米

程序:

feet = eval(input(“Enter a value for feet:”))
meters=feet*0.305
print(feet,”feet is”,meters,”meters”)

结果:

Enter a value for feet:16.5
16.5 feet is 5.0325 meters

《python语言程序设计》_第二章编程题

2.4

磅数 转换成千克数,一磅等于0.454千克

程序:

feet = eval(input(“Enter a value for feet:”))
meters=feet*0.305
print(feet,”feet is”,meters,”meters”)

结果:

Enter a value for feet:16.5
16.5 feet is 5.0325 meters

《python语言程序设计》_第二章编程题

2.5

编写一个读取小计和酬金然后计算小费以及合计金额的程序,如果用户键入的小计是10,酬金率是15%,程序就会显示是1.5,合计金额是11.5

《python语言程序设计》_第二章编程题

程序:

subtotal,gratuityRate=eval(input(“Enter the subtotal and a gratuity rate:”))
gratuity= subtotal*gratuityRate/100
total=gratuity+subtotal
print(“The gratuity is”,gratuity,”and the total is”,total)

结果:

Enter the subtotal and a gratuity rate:15.69,15
The gratuity is 2.3535 and the total is 18.043499999999998

《python语言程序设计》_第二章编程题

2.6  读取一个0到1000之间的整数并计算它各位数字之和,例如:如果一个整数是932,那么它各位数字之和就是14。(提示:使用%来提取数字,使用//运算符来去除被提取的数字。例如:932%10=2而932//10=93)

程序:

A=eval(input(“Enter a numer between 0 and 1000:”))
b=A%10 #运算符%求余符号,A%100得到的余数是A的个位数,int()函数表示去掉了浮点数,取整
c=A//100 #运算符//是表示整除,得到的相当于A的百位数
d=(A-100*b-c)/10    #或者,(((A-b)/10)%10)  
print(“The sum of the digits is”,int(b+c+d))

结果:

Enter a numer between 0 and 1000:999
The sum of the digits is 27

《python语言程序设计》_第二章编程题

2.7 输入分钟数,计算年数和天数

答案略

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844