Python学习Task02:条件循环结构

练习题Python学习Task02:条件循环结构_第1张图片

答:

>>> x = [i for i in range(1500,2700) if i%7==0 and i%5==0]
>>> print(x)
[1505, 1540, 1575, 1610, 1645, 1680, 1715, 1750, 1785, 1820, 1855, 1890, 1925, 1960, 1995, 2030, 2065, 2100, 2135, 2170, 2205, 2240, 2275, 2310, 2345, 2380, 2415, 2450, 2485, 2520, 2555, 2590, 2625, 2660, 2695]
>>> 

Python学习Task02:条件循环结构_第2张图片
答:

v1,v2,t,s,L = map(int,input("请输入用空格隔开的五个正数(兔子的速度v1、乌龟的速度v2、兔子领先t米休息s秒、赛道的长度L):").split())
if not((0<v1<=100 and 0<v2<=100) and (0<t<=300) and (0<=s<=10) and (0<L<=10000)):
    print("输入错误!")
turtle = 0
rabbit = 0
time = 0
while (turtle<L) and (rabbit<L):
    if rabbit - turtle >=t:   #兔子休息
        time += s
        turtle += v2 * s
    else:
        rabbit += v1
        turtle += v2
        time += 1
    
if turtle<rabbit:         
    print('R')
elif turtle==rabbit:
    print('D')
else:
    print('R')
print(time)

你可能感兴趣的:(Python学习Task02:条件循环结构)