day3作业

print('n = 6789, 写代码获取变量n中百位上的数')
num = 6789
hundreds_place = (num // 100) % 10
print('百位数是:',hundreds_place) 
print('-------------------------------------------------------------------------------')

print('n = 12345, 写代码获取变量n中每一位上的数')
num = 12345
ones_place = num % 10
tens_place = (num // 10) % 10
hundreds_place = (num // 100) % 10
thousands_place = (num // 1000) % 10
ten_thousands_place = num // 10000
print('个位是:',ones_place)
print('十位是:',tens_place)
print('百位是:',hundreds_place)
print('千位是:',thousands_place)
print('万位是:',ten_thousands_place)
print('-------------------------------------------------------------------------------')

print('写出判断一个数是否能同时被3和7整除的条件语句')
num = int(input('输入一个整数:'))
if (num % 3 == 0) and (num % 7 == 0):
    print(num,'能同时被3和7整除')
else:
    print(num,'不能同时被3和7整除')
print('-------------------------------------------------------------------------------')

print('写出判断一个数是否能够被3或者7整除,但是不能同时被3或者7整除')
num = int(input('输入一个整数:'))
if (num % 3 == 0) and (num % 7 == 0):
    print(num,'能同时被3和7整除')
elif (num % 3 == 0) or (num % 7 == 0):
    print(num,'能够被3或者7整除,但不能同时被3和7整除')
else:
    print(num,'既不能被3整除也不能被7整除')
print('-------------------------------------------------------------------------------')

print('输入年,写代码判断输入的年是否是闰年,如果是输出\'闰年\',否则输出\'不是闰年\'')
num = int(input('输入一个四位年份:'))
if num % 400 == 0:
    print('闰年')
elif num % 4 == 0:
    if num % 100 != 0:
        print('闰年')
    else:
        print('不是闰年')
else:
    print('不是闰年')
print('-------------------------------------------------------------------------------')

print('今天上课讲了1500秒的课,编程计算今天上课时间是多少小时,多少分钟,多少秒')
time_total = 1500
time_seconds = time_total % 60
time_minutes = (time_total // 60) % 60
time_hours = time_total // 3600
print('今天上课时间是',time_hours,'时',time_minutes,'分',time_seconds,'秒')
print('-------------------------------------------------------------------------------')

print('定义两个变量保存一个人的身高和体重,编程实现判断这个人的身材是否正常!')
print('公式: 体重(kg)/身高(m)的平方,值在18.5 ~ 24.9之间属于正常。')
height = float(input('输入身高(米):'))
weight = float(input('输入体重(千克):'))

value = weight / height ** 2
if 18.5<= value <= 24.9:
    print('身材正常')
else:
    print('身材不正常')

运行结果:

作业结果.png

你可能感兴趣的:(day3作业)