[英]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.