unindent与任何外部缩进级别都不匹配-学校作业

时间:2019-06-04 12:40:17

标签: python python-3.6

所以基本上,我坚持使用我的代码,这是用于家庭作业,我不知道如何解决我遇到的错误 “ unindent不匹配任何外部缩进级别” 我已经尝试过自己修复它,但没有取得任何成功,所以我正在与愿意帮助我的任何人联系。

这是我的代码

exit = False
while not exit:
  #variables
  name=str(input("Enter your students name "))

  #User ratings for rolleston spirit
  DSR=int(input("Enter rating for Develop Self "))
  BCR=int(input("Enter rating for Building Communities "))
  TFR=int(input("Enter rating for Transforming Futures "))    

  #If the input is above a certain number, it will print the student is doing well and if an input is below a ceratin number it will print the student needs support in .....
  if DSR>=6:
    print (name, "is doing well in developing self")
  elif DSR<4:
    print (name," needs support in developing self")
  if BCR>=6:
    print (name, "is doing well in Building Communities")
  elif BCR<4:
    print (name," needs support in Building Communities")
  if TFR>=6:
    print (name, "is doing well in Transforming Futures")
  elif TFR<4:
    print (name," needs support in Transforming Futures")

  #Function to find the highest number in a list
  def maxi(items):
  #max finds the highest number in a list
   return max(items)
  print(name, "highest score was ", maxi([DSR, BCR, TFR]))

#function to get average of a list 
  def Average(lst): 
      return sum(lst) / len(lst) 
# Creating List 
  lst = [DSR, BCR, TFR] 
  average = Average(lst) 
# Printing average of the list 
  print(name, "has an overall rating of ", round(average, 2))
  rep=str(input("Do you wish to continue? Y/N "))

 if rep=="Y":
   print ("  ")
 elif rep =="N":
   exit = True
print("  ")

代码的预期输出。

Enter your students name Name
Enter rating for Develop Self 3
Enter rating for Building Communities 7
Enter rating for Transforming Futures 9
Name  needs support in developing self
Name is doing well in Building Communities
Name is doing well in Transforming Futures
Name highest score was  9
Name has an overall rating of  6.33
Do you wish to continue? Y/N

1 个答案:

答案 0 :(得分:1)

您的代码中可能会有空格和制表符混合,并且您需要4个空格来缩进。试试这个:

exit = False
while not exit:
    #variables
    name=str(input("Enter your students name "))

    #User ratings for rolleston spirit
    DSR=int(input("Enter rating for Develop Self "))
    BCR=int(input("Enter rating for Building Communities "))
    TFR=int(input("Enter rating for Transforming Futures "))    

    #If the input is above a certain number, it will print the student is doing well and if an input is below a ceratin number it will print the student needs support in .....
    if DSR>=6:
        print (name, "is doing well in developing self")
    elif DSR<4:
        print (name," needs support in developing self")
    if BCR>=6:
        print (name, "is doing well in Building Communities")
    elif BCR<4:
        print (name," needs support in Building Communities")
    if TFR>=6:
        print (name, "is doing well in Transforming Futures")
    elif TFR<4:
        print (name," needs support in Transforming Futures")

#Function to find the highest number in a list
def maxi(items):
    #max finds the highest number in a list
    return max(items)
print(name, "highest score was ", maxi([DSR, BCR, TFR]))

#function to get average of a list 
def Average(lst): 
    return sum(lst) / len(lst) 
# Creating List 
lst = [DSR, BCR, TFR] 
average = Average(lst) 
# Printing average of the list 
print(name, "has an overall rating of ", round(average, 2))
rep=str(input("Do you wish to continue? Y/N "))

if rep=="Y":
    print ("  ")
elif rep =="N":
    exit = True
print("  ")