python中if后面为什么用冒号_if语句中冒号的语法错误

我是python新手,我正在制作一种游戏,作为我的第一个项目之一,它猜测1到10之间的数字,然后用户猜测它。他们有三个猜测,程序会告诉用户下一个猜测是否需要更高或更低。代码中出现错误的部分并不重要,因为如果用户两次输入相同的答案,允许他们第一次重复猜测,但不允许第二次重复猜测,这只会使猜测不被浪费。在代码上,我已经标记出问题所在。就像我说的,我对python很陌生,这可能是一些业余的noobie错误。提前谢谢。import time # This imports the time module.

import random # This imports the random module.

MyNumber = random.randrange(1,10) # This picks a number for the variable 'MyNumber'

firstGuess = int(input('Ok then, we shall begin! What is your first guess?'))

print()

if firstGuess == (MyNumber):

print('Well done! You win!')

time.sleep(3)

exit()

if firstGuess < MyNumber:

print('Go Higher!')

time.sleep(1)

if firstGuess > MyNumber:

print('Go Lower!')

time.sleep(1)

print()

secondGuess = int(input('Better luck this time! What is your second guess?'))

print()

if secondGuess == firstGuess:

print('You tried that one last time! Don\'t worry, I won\'t count that one!')

bungled = (1)

secondGuess = int(input('What is your second guess?')

if secondGuess == firstGuess: # This colon is causing the problem. <===========

print('You\'ve already tried that one twice!')

bungled = (2)

if secondGuess == MyNumber:

print('Well done! You win!')

time.sleep(3)

exit()

if secondGuess < MyNumber:

print('Go Higher!')

time.sleep(1)

if secondGuess > MyNumber:

print('Go Lower!')

time.sleep(1)

print()

thirdGuess = int(input('This is your final chance! What is your third guess?'))

print()

if thirdGuess == MyNumber:

print('Well done! You win!')

time.sleep(3)

exit()

if thirdGuess < MyNumber:

MyNumber = str(MyNumber)

print('Sorry! You lost! The number was '+MyNumber)

time.sleep(1)

exit()

if thirdGuess > MyNumber:

MyNumber = str(MyNumber)

print('Sorry! You lost! The number was '+MyNumber)

time.sleep(1)

exit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值