猜数游戏猜中时报错怎么回事,求大佬康康
"""use python make first game"""import random
counts = 1
answer = random.randint(1,10)
while counts < 10:
temp = input("")
guess = int(temp)
if guess < answer:
print("遗憾,太小了")
elif guess > answer:
print("遗憾,太大了")
else:
print("预测"&counts&"次,你猜中了!")
break
counts = counts + 1
猜中时老报错这是咋回事里?求大佬解答
报错信息:
Traceback (most recent call last):
File "H:\系统默认\桌面\工作\Python工程\game.py", line 13, in <module>
print("预测"&counts&"次,你猜中了!")
TypeError: unsupported operand type(s) for &: 'str' and 'int' print("预测"&counts&"次,你猜中了!")
改成
print("预测" + str(counts) + "次,你猜中了!") """use python make first game"""
import random
counts = 1
answer = random.randint(1,10)
while counts < 10:
temp = input("")
guess = int(temp)
if guess < answer:
print("遗憾,太小了")
elif guess > answer:
print("遗憾,太大了")
else:
print(f"预测{counts}次,你猜中了!")
break
counts = counts + 1
一楼正确
页:
[1]