练习题
2.1.编写以一个python程序来查找那些可以被7除以5的整数的数字,介于1500到2700之间。
t = 1500
for i in range(1500, 2700):
if i % 7 == 0 and i % 5 ==0:
print(i)
t +=1
2.2.龟兔赛跑
v1,v2,t,s,l = map(int,input().split())
if v1<=100 and v2<=100 and t<=300 and s<=10 and l<=10000 and l%v1==0 and l%v2==0:
s1,s2,i = 0,0,0
while s1<l and s2<l:
s1,s2,i=v1+s1,v2+s2,i+1
if s1==l or s2==l:
break
elif s1-s2>=t:
s2,i=s2+v2*s,i+s
if s1>s2:
print('R')
print(i)
if s1==s2:
print('D')
print(i)
if s1<s2:
print('T')
print(int(l/v2))
3.猜数字游戏
import random #random库主要用于产生各种分布的伪随机数序列,使用random库的主要目的是生成随机数
Set_number = random.randint(0,100)
print(Set_number)
Guess_number = int(input("请输入:"))
N = 1
while(Guess_number < Set_number or Guess_number > Set_number):
N = N + 1
if Guess_number > Set_number:
print("太大")
elif Guess_number < Set_number:
print("太小")
Guess_number = int(input("输入错误"))
print("恭喜你猜到了这个这个数是".format(N))