python第一课的课后练习总结

python第一课练习题

课后练习

第一题

  • 没什么好说的,注意小数点后只保留有效数字即可。
n = float(input("Enter a degree in celsius:"))
fahrenheit = ( 9 / 5 ) * n + 32
print("%g Celsius is %g Fahrenheit" % ( n , fahrenheit ))

第二题

  • 需要注意题中输入是用逗号隔开。然后调用math函数中的π,做运算即可。
import math
r , h = map( float , input('Enther the radius and length of acylinder:').split(',') )
s = math.pi * r * r
t = s * h
print('The area is %g' %s)
print('The volume is %g'%t)

在这里插入图片描述

第三题

y = float(input("Enter a volue for feet:"))
m = y * 0.305
print("%g feet is %g meters" %( y , m ))

第四题

  • 注意保留小数点后一位
m = float(input("Enter a amount of water in kilograms:"))
c = float(input("Enter a initial temperature:"))
z = float(input("Enter a final temperature:"))
q = m * ( z - c ) * 4184
print("The energy needed is %.1f" %q )

在这里插入图片描述

第五题

c,l = map( float , input( "Enter balance and interest rate(e.g., 3 for 3%): " ).split(',') )
s = c * ( l / 1200 )
print("The interest is %g" %s )

第六题

v0,v1,t = map(float,input("Enter v0,v1, and t:").split(','))
a = ( v1 - v0 ) / t
print("The average acceleration is %g" %a )

在这里插入图片描述

第七题

m = float(input("Enter the monthly saving amount:"))
n = 0
s=0
while s < 6 :
    n = ( n + m ) * (1.0+0.00417)
    s = s + 1
print("The average acceleration is %g" %n )

第八题

m = int(input("Enter a number between 0 and 1000 :"))
s = 0
while m > 0:
    if m > 0 :
        s = s + m % 10
        m = m // 10
print("The sum of the digits is %d" %s ) 

在这里插入图片描述

第九题

s = 25.0 / 4.0
d = 25 / 4
print("25/4d等于%g" % s )
print('将其转变为整数为%d' % d)


m = int( input("输入一个需要判断奇偶的数:") )
if m % 2 == 0 :
    print( '{0}是偶数'.format(m) )
else :
    print( '{0}是奇数'.format(m) )


t = int( input("输入一个秒数:") )
f = t // 60
miao = t % 60 
print('%d转换成分和秒等于: %d分%d秒' % ( t , f , miao ) )

weekday = int ( input("请输入今天是星期几:") )
daytime = int ( input("请输入想知道几天后是星期几:") )
day = daytime % 7
week = 0 - ( 7 - weekday ) + day
print('10天以后是星期%d' % week)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值