Chi*_*imp 16 python python-3.x
我是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()
Run Code Online (Sandbox Code Playgroud)
Ole*_*pin 31
它实际上不是结肠.它是前一行的未闭合括号.
当你变得奇怪时SyntaxError,检查前面的支架平衡.
| 归档时间: |
|
| 查看次数: |
40333 次 |
| 最近记录: |