python学习-游戏
短信预约 -IT技能 免费直播动态提醒
#coding : utf-8
#这是一个猜数字游戏
import random
guessesTaken = 0 #赋予初始值
print('hello what is you name?') #输入玩家姓名
myName = input() #从键盘接收一个值
number = random.randint(1,20) #定义数字范围
print('well,'+myName+',i am thinking of a number between 1 and 20.')
while guessesTaken < 6: #接收键盘的次数
print('Task a guess.')
guess = input() #从键盘接收一个值
guess = int(guess) #定义值为int类型
guessesTaken = guessesTaken +1
if guess < number:
print('your guess is too low.')#打印输出值,过低
if guess > number:
print('Your guess is too high.')#打印输出值,过高
if guess == number:
break
if guess == number: #猜对了输出
guessesTaken = str(guessesTaken)
print('good job,'+ myName + '! you guessed my number in '+ guessesTaken + 'guesses!')
if guess != number: #不等于输入值输出
number = str(number)
print('Nope. the number i was thinking of was '+ number)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341