Python 3.x 如何修复错误:应为缩进块
我一直收到这样一条错误消息,上面说Python 3.x 如何修复错误:应为缩进块,python-3.x,indentation,Python 3.x,Indentation,我一直收到这样一条错误消息,上面说需要一个缩进块。 外壳突出显示粗体点作为错误。有没有关于如何修复它的建议? 我只是一个初学者,所以任何和所有的帮助将不胜感激!提前谢谢你 from random import * s = choice( [ 'rock', 'paper', 'scissors' ]) def rps( ): """ runs a game of Rock Paper Scissors between the program and the user by returning
需要一个缩进块
。
外壳突出显示粗体点作为错误。有没有关于如何修复它的建议?
我只是一个初学者,所以任何和所有的帮助将不胜感激!提前谢谢你
from random import *
s = choice( [ 'rock', 'paper', 'scissors' ])
def rps( ):
""" runs a game of Rock Paper Scissors between the program and the user by returning the user's choice and the program's choice and signaling a winner
input: the user's choice which is one of three responses in the game Rock-Paper- Scissors - all are a string of letters
"""
print ('rps( )')
print ('Welcome to a game of Rock Paper Scissors!')
print ('I just made my choice.')
print ('I promise no cheating this time!')
r = input('Now you choose rock, paper, or scissors!')
print
如果r==“纸张”:
好的。。。所有这一切都令人困惑 首先,函数
rps()
中除了注释之外没有任何内容。以下是定义函数的方式:
def hi_im_a_function():
hi im inside the function
hi, im not inside the function.
hi_im_a_function()
^调用函数
事实上,整个功能似乎已经过时。我不知道你想用print('rps()')
这个东西实现什么,但它什么都没做。我建议你放下它
错误来自错误前一行上的随机浮动打印。如果r==paper
行中出现错误,则该错误将出现在行中,因为这是编译器第一次感受到您在它前面的行中设置的错误的影响的地方
和以前一样,我不知道你想在那里做什么,但那句话没有任何意义。删除它
修复这些错误,它应该像一个符咒一样工作。我想我已经修复了它
从随机导入*
s=选择([‘石头’、‘布’、‘剪刀’]))
def rps():
“”“通过返回用户的选择和程序的选择并发出赢家的信号,在程序和用户之间运行一个石头剪刀游戏
从技术上讲,该函数没有输入,也没有返回值;该函数是用户和程序之间的交互
“”“
为什么向下投票…??错误是哪一行?我认为现在应该修正格式。我认为我在那之后缩进正确,但它一直给我错误。我不确定问题出在哪里。您似乎忘记了第三次elif
结束时的)
,它只是说print('我们需要重新匹配!'
我想在开始时打印函数名和信息。我知道它在rps()中没有输入,所以为什么()是空的,但你是说我需要在那之后缩进所有内容,以使其成为函数的一部分吗?是的。所有内容都需要缩进。看起来你在最新答案中做得很好。太好了!现在你介意选择我的答案作为正确答案,这样我就可以享有声誉吗?:D
def hi_im_a_function():
hi im inside the function
hi, im not inside the function.
hi_im_a_function()
print ('Welcome to a game of Rock Paper Scissors!')
print ('I just made my choice.')
print ('I promise no cheating this time!')
r = input('Now you choose rock, paper, or scissors!')
if r == 'paper':
print ('You chose paper.')
if s == 'scissors':
print ('I chose scissors. Haha, I win fair and square!')
elif s == 'rock':
print ("I chose rock. Maybe I'll have better luck next time...")
elif s == 'paper':
print ('We need a rematch!')
elif r == 'scissors':
print ('You chose scissors.')
if s == 'rock':
print ('I chose rock. Haha, I win fair and square!')
elif s == 'paper':
print ("I chose paper. Maybe I'll have better luck next time...")
elif s == 'scissors':
print ('We need a rematch!')
elif r =='rock':
print ('You chose rock.')
if s == 'paper':
print ('I chose paper. Haha, I win fair and square!')
elif s == 'scissors':
print ("I chose scissors. Maybe I'll have better luck next time...")
elif s == 'rock':
print ('We need a rematch!')
else:
print ("Don't you know the rules? Choose rock, paper or scissors!")