python简单习题3

1. 输入三角形三个边,判断能否构成一个三角形

两边之和大于第三边

a = float(input('a '))
b = float(input('b '))
c = float(input('c '))
judge = True if a + b > c and a + c > b and b + c > a else False
if judge:
    print('能构成三角形')
else:
    print('不能构成三角形')

a 1
b 2
c 3
不能构成三角形

2. 输入一个年份,比如2020,判断是否是闰年。

def year():
    y = int(input("请输入年份:"))
    judge = (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0)
    if judge:
        print(y, '年是闰年')
    else:
        print(y, '年不是闰年')
    year()

year()

请输入年份:2020
2020 年是闰年
请输入年份:2000
2000 年是闰年
请输入年份:2019
2019 年不是闰年

3. 获取当前系统时间,判断是上午,下午还是晚上。如果是上午,输出“Good morning!",否则输出”Good afternoon!“,如果是晚上输出”Good evening!“。

import datetime 
hour = datetime.datetime.now().hour
# hour = int(input('输入'))
print(hour)
if 0 <= hour <= 12:
    print('Good morning!')
elif 12 < hour <= 18:
    print('Good afternoon!')
else:
    print('Good evening!')

13
Good afternoon!

第三个没有写的太精细,上下午分界不明显。

:- )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值