我是靠谱客的博主 无限老虎,这篇文章主要介绍python—基础入门练习题01,现在分享给大家,希望可以做个参考。

 目录

1、题目:(将摄氏温度转化为化氏温度)编写一个从控制台读取摄氏温度并将它转变为 化氏温度并予以显示的程序。

2、题目: (计算圆柱的体积) 编写一个读取圆柱的半径和高并利用下面的公式计算圆柱体底面积和体积的程序:

3、题目:(对一个整数中的各位数字求和) 编写一个程序,读取一个0到1000之间的整数并计算它各位数字之和。

4、题目:(计算年数和天数) 编写一个程序:提示用户输入分钟数(例如:1 000 000),然后将分钟 转换为年数和天数并显示的程序。为了简单起见,假定一年365天。

5、题目:(科学:计算能量) 编写一个程序,计算将水从初始温度加热到最终温度所需的能量。你的程序应该 提示用户输入以千克计算的水量以及谁的初始温度和最终温度


1、题目:(将摄氏温度转化为化氏温度)编写一个从控制台读取摄氏温度并将它转变为 化氏温度并予以显示的程序。

转换公式如下: 

fahrenheit = (9 / 5 )* Celsius + 32

复制代码
1
2
3
fahrenheit:华氏温度 Celsius: 摄氏温度 degree:度
复制代码
1
2
3
执行目标: Enter a degree in Celsius:43 43 Celsius is 109.4 Fahrenheit
复制代码
1
2
3
4
代码: Celsius = float(input("Enter a degree in Celsius:")) fahrenheit = (9 / 5) * Celsius + 32 print("%.0f Celsius is %.1f Fahrenheit" % (Celsius, fahrenheit))

执行结果:

2、题目: (计算圆柱的体积) 编写一个读取圆柱的半径和高并利用下面的公式计算圆柱体底面积和体积的程序:

公式:

复制代码
1
2
area(地区) = radius(半径) * radius * Π volume(体积) = area * length(高)

 执行目标:

复制代码
1
2
3
Enter the radius length of a cylinder:5.5,12 The area is 95.0331 The volume is 1140.4
复制代码
1
2
3
4
5
代码: rad, len = eval(input("Enter the radius length of a cylinder:")) area = rad * rad * 3.1415926 volume = area * len print("The area is %.4fnThe volume is %.1f" % (area, volume))

运行结果:

3、题目:(对一个整数中的各位数字求和) 编写一个程序,读取一个0到1000之间的整数并计算它各位数字之和。

复制代码
1
2
3
执行目标: Enter a number between 0 and 1000 :999 The sum of the digits is 27
复制代码
1
2
3
4
5
6
7
8
9
10
11
num = int(input("Enter a number between 0 and 1000:")) #如果要不局限于正数,那么可以加入: num = abs(num) #求绝对值 num1 = num % 10 num = num // 10 num2 = num % 10 num = num // 10 num3 = num % 10 #可以将上面两行去除,改为:num3 = num // 10 ,两种方法都可行 sum = num1 + num2 + num3 #sum为内置函数,除非后面全程用不到,否则不宜为变量 print("The sum of the digits is ", sum)

执行结果:

4、题目:(计算年数和天数) 编写一个程序:提示用户输入分钟数(例如:1 000 000),然后将分钟 转换为年数和天数并显示的程序。为了简单起见,假定一年365天。

复制代码
1
2
3
执行目标: Enter the number of minutes:1000000000 1000000000 minutes is approximately 1902 years and 214 days

复制代码
1
2
3
4
5
代码: minutes = int(input("Enter the number of minutes:")) years = minutes // (365 * 24 * 60) days = (minutes % (365 * 24 * 60)) // (24 * 60) print("1000000000 minutes is approximately %d years and %d days" % (years, days))

执行结果:

5、题目:(科学:计算能量) 编写一个程序,计算将水从初始温度加热到最终温度所需的能量。你的程序应该 提示用户输入以千克计算的水量以及谁的初始温度和最终温度

复制代码
1
2
3
计算能量公式: finalTemperature :最终的 (最终温度) initialTemperature:首字母 (初始温度)
复制代码
1
2
3
4
5
执行标准: Enter the amount of water in kilograms:55.5 Enter the initial temperature:3.5 Enter the final temperature:10.5 The energy needed is 1625484.0
复制代码
1
2
3
4
5
6
代码: M = float(input("Enter the amount of water kilograms:")) initial = float(input("Enter the initial temperature:")) final = float(input("Enter the final temperature:")) Q = M * (final - initial) * 4184 print("The energy needde is ", Q)

执行结果:

最后

以上就是无限老虎最近收集整理的关于python—基础入门练习题01的全部内容,更多相关python—基础入门练习题01内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部