#this is a guess a the number game import random secretNumber=random.randint(1,20) print ('I am thinking of a number between 1 and 20.') #Ask the player to guess 6 times. for guessesTaken in range(1,7): print('Take a guess.') guess=int(input()) if guess<secretNumber: print('your number is too low') elif guess>secretNumber: print('your number is too high') else: break if guess==secretNumber: print ('Good') else: print('Nope.The number I was thinking of was '+str(secretNumber)) secretNumber是随机生成的1到20之间的一个数,for循环里就是可以猜六次,六次之内猜中了就执行break语句从循环中跳出来,如果六次机会用完就输出正确的数字
python学习过程随笔
最新推荐文章于 2024-03-04 15:56:51 发布