题目要求:在1-20中随机生成一个数字,你来猜,只有6次机会. 举例一: #!/usr/bin/python # -*- coding: UTF-8 -*- import random secretNumber=random.randint(1,20) print "I'm thinking of a number between 1 and 20." times = 0 for i in range(1,7): print "Take a guess:" gues…
import random number = int(random.uniform(1,10)) attempt = 0 while (attempt < 3): m = int(input('Please try to guess the number!')) if m == number: print('bingo!') break elif m < number: print('Your answer is smaller!') attempt += 1 else: print('You…
猜数字游戏 系统生成一个100以内的随机整数, 玩家有6次机会进行猜猜看,每次猜测都有反馈(猜大了,猜小了,猜对了-结束) 6次中,猜对了,玩家赢了. 否则系统赢了 #!/usr/bin/env python import random secret=random.randint(1,100) guess=0 tries=0 print "This game is to guess a number for you!" print " It is a number f…
2015.5.25第一天下载Python IDLE,写个猜数字的小游戏来熟悉这门语言: times=6 letters=[100] for i in range(1,times): a = input("input the number you guess:") try: b = int(a) if isinstance(b,int): if i <5: if int(a) in letters: print("%s is the right answer, you w…