![](/img/trans.png)
[英]I'm trying to make a rock paper scissors game in python, but am getting an unindent does not match any outer indent lever error
[英]I've just started python and I'm trying to make a Rock ,Paper ,Scissors game and I can't work out how to change the font and its size
这是我的代码,如果有人可以提供帮助,那将是非常重要的。
import random
a = ["rock", "paper", "scissors"]
def game():
while True:
try:
word = input('Enter rock, paper, or scissors: ')
if word not in a:
raise ValueError # this will send it to the print message and back to the input option
break
except ValueError:
print(" You must enter rock, paper, or scissors.")
comp_draw = random.choice(a)
print('The computer drew ' + comp_draw)
if comp_draw == 'rock' and word =='rock':
print('It was a tie')
elif comp_draw == 'paper' and word =='paper':
print('It was a tie')
elif comp_draw == 'scissors' and word =='scissors':
print('It was a tie')
elif comp_draw == 'paper' and word =='rock':
print('GAME OVER')
elif comp_draw == 'rock' and word =='paper':
print('you won!')
elif comp_draw == 'rock' and word =='scissors':
print('GAME OVER')
elif comp_draw == 'scissors' and word =='rock':
print('you won!')
elif comp_draw == 'scissors' and word =='paper':
print('GAME OVER')
elif comp_draw == 'scissors' and word =='rock':
print('you won!')
if __name__ == "__main__":
game()
while True:
if input('Would you like to play_again? ') == 'yes':
game()
else:
break
font = 'Arial (sans-serif)' : 'normal'
'weight' : 'bold',
'size' : 99}
这就是我尝试更改字体的方式
font = 'Arial (sans-serif)' : 'normal'
'weight' : 'bold',
'size' : 99}
这是我收到的错误信息
IndentationError: unindent does not match any outer indentation level on line 48 font = 'Arial (sans-serif)': 'normal' ^ 在 main.py
为了使代码正常工作,您需要取消缩进字体,在“normal”之后添加一个逗号并添加一个左大括号:
if __name__ == "__main__":
game()
while True:
if input('Would you like to play_again? ') == 'yes':
game()
else:
break
font = {'Arial (sans-serif)' : 'normal' ,
'weight' : 'bold',
'size' : 99}
但是,您没有使用字体变量,因此它不会改变任何内容。 如前所述,如果您要打印到终端,则无法更改 python 中的字体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.