1 import random 2 3 """ 4 #查看源代码日后爬虫用 5 import urllib.request 6 7 # coding=utf-8 8 9 url = "http://www.baidu.com" 10 data = urllib.request.urlopen(url).read() 11 data = data.decode('UTF-8') 12 13 print(data) 14 15 # print练手 16 x = 5 / 2 17 y = 3 / 2 18 19 print('x为', x, ' ', 'y为', y) 20 print('x和y分别为%.1f,%.1f' % (x, y)) 21 22 for z in range(1, 11): 23 print('{0:5d} {1:5d} {2:4d}'.format(z, z * z, z * z * z)) 24 25 print("what? ?" + " water") 26 print(5 + 8) 27 """ 28 # if else语句练手 29 30 31 Help = '大了' 32 Help2 = '小了' 33 gmAnswer = 12450 34 key = random.randint(1, 10) 35 gmAnswer = key 36 life = 3 37 38 while life > 0: 39 userAnswer = int(input('随便给个整数')) # 直接将输入的str转换成int并赋值 40 if userAnswer < gmAnswer: 41 print(Help2) 42 elif userAnswer > gmAnswer: 43 print(Help) 44 else: 45 print('you win') 46 break 47 life -= 1