一, import random 2 ''' 3 定义一个字符串"python的创始人是Guido",试分别打印出"Guido","odiuG", "ph的人uo" 4 ''' 5 a = 'python的创始人是Guido' 6 print(a[-5:]) 7 print(a[-1:-6:-1]) 8 print(a[::3]) 9 '''二, 10 7.有字符串"你"和"最帅",如何得到字符串"你最帅",又如何得到字符串"你最帅最帅最帅" 11 ''' 12 a = '你' 13 b = '最帅' 14 print(a+b) 15 print(a+3*b)
三, for i in range(10): 3 a = random.randint(0,1000) 4 b = [] 5 for i in range(3): 6 b.append(a%10) 7 a = a//10 8 if b[0]==b[2] and b[2]!=0 and b[0]!= 0 or b[0]==b[1]and b[2]==0 and b[0]!=0: 9 print(b[2]*100+b[1]*10+b[0])
四, a = 300 2 b = 15 3 c = 9 4 d = 1 5 for i in range(0,20): 6 for e in range(0,34): 7 for f in range(0,300): 8 if i * b + e * c + d * f ==300 and i + e + f == 100: 9 print('买大公鸡{}只,母鸡{}只,小鸡{}只'.format(i,e,f))
五, a = input('请输入一个字符串:') 2 b = 0 3 c = 0 4 for i in range(len(a)): 5 if 65 <=ord(a[i]) <= 90 or 97 <= ord(a[i]) <= 122: 6 b += 1 7 else: 8 c += 1 9 print(b,c)
六, a,b =eval(input('请输入年份月份:')) 2 x = 0 3 z = 0 4 for i in range(1990,a): 5 6 7 if i % 4 == 0 and i % 100 != 0 or i % 400 ==0: 8 x += 366 9 else: 10 x += 365 11 print(x) 12 for i in range(1,b): 13 if a % 4 == 0 and a % 100 != 0 or a % 400 ==0: 14 if i in (1,3,5,7,8,10,12): 15 d = 31 16 elif i in (4,6,9,11): 17 d = 30 18 else: 19 d = 29 20 else: 21 if i in (1,3,5,7,8,10,12): 22 d = 31 23 elif i in (4,6,9,11): 24 d = 30 25 else: 26 d = 28 27 z = z+d 28 print(z) 29 y = x + z 30 print(y) 31 h = y % 7 32 if h == 0: 33 print('周一') 34 elif h ==1: 35 print('周二') 36 elif h ==2: 37 print('周三') 38 elif h ==3: 39 print('周四') 40 elif h ==4: 41 print('周五') 42 elif h ==5: 43 print('周六') 44 elif h ==6: 45 print('周日')