我是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()

推荐答案

实际上不是结肠.这是前一行中未闭合的括号.

当你得到一个奇怪的SyntaxError,判断之前的支架平衡.

Python-3.x相关问答推荐

将strid()映射到Pandas DataFrame中的字符串不会更改NaN条目,但仍然声称它们不同?

以编程方式关闭jupyterlab内核

PythonPandas READ_EXCEL空数据帧

根据按不同列中的值分组的平均值划分 DataFrame

合并问卷中多列中的稀疏问题 - Pandas

如何在带有 GUI 的 python 游戏中设置回答时间限制?

在python中循环处理时并行写入文件

pip install mysqlclient 失败为 mysqlclient 运行 setup.py bdist_wheel ... 错误

二进制文件的 Python 3 和 base64 编码

Generic[T] 基类 - 如何从实例中获取 T 的类型?

如何使用 asyncio 添加连接超时?

python 3的蓝牙库

Python 3 - Zip 是 pandas 数据框中的迭代器

清除 PyCharm 运行窗口

在 linux mint 上安装 python3-venv 模块

如何将文档字符串放在 Enums 上?

同步调用协程

python asyncio add_done_callback 与 async def

在 Meta 中创建具有动态模型的通用序列化程序

十六进制字符串到 Python 3.2 中的带符号整数?