首页 > 编程语言 > 详细

Python 习题

时间:2020-05-31 18:50:48      阅读:35      评论:0      收藏:0      [点我收藏+]

1、输入某年某月某日,判断这一天是这一年的第几天?

leap_year = [31,29,31,30,31,30,31,31,30,31,30,31]#闰年
common_year = [31,28,31,30,31,30,31,31,30,31,30,31]#平年
year = int(input("type the year:"))
month = int(input("type the month:"))
day = int(input("type the day:"))
sum = 0


if (year%4==0) and (year%100!=0) or (year%400==0):
    for i in range(0,month-1):
        sum +=leap_year[i]
    print("it‘s the {}th day".format(sum+day))
else:
    for i in range(0,month-1):
        sum +=common_year[i]
    print("it‘s the {}th day".format(sum+day))

2、输入三个整数x,y,z,请把这三个数由小到大输出。

x = int(input("type a number:"))
y = int(input("type a number:"))
z = int(input("type a number:"))
print(sorted([x,y,z]))

 3、九九乘法表。

for i in range(1,10):for j in range(1,i+1):
        print("{}*{}={}\t".format(i,j,i*j),end="")
    print()

4、暂停一秒输出。

import time
import random

for i in range(10):
    print(i)
    time.sleep(random.randint(0,9))

5、

 

Python 习题

原文:https://www.cnblogs.com/yijierui/p/13019523.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!