为什么我的代码缩进不正确?

时间:2018-06-21 02:49:50

标签: python python-3.x indentation

我的[Python 3.6]代码遇到了一些麻烦。我不确定发生了什么问题,并且我尝试了多种方法来修复它,但没有任何效果。

问题出在“ Class Mainarchive:”这一行,我认为这是缩进错误

import time
print("Welcome to Code Vault Abraxis")
time.sleep(1)

class Username:
  print()
  username1 = input("Username: ")
  username2 = ("AbraxisUser")

  while username1 != username2:
    time.sleep(1)
    print()
    username1 = input("Username does not exist. Username: ")

class Password:
  time.sleep(1)
  print()
  password1 = input("Password:  ")
  password2 = ("cats")

  while password1 != password2:
   time.sleep(1)
   print()
   password1 = input("Wrong Password! Try again. Password: ")

这是问题所在

class Mainarchive:
  def secrets(sec):
  time.sleep(2)
    print("1.")
    print("2.")
    print("3.")
    print("4.")
    print("5.")
def projects(pro):
time.sleep(2)
  print("1.")
  print("2.")
  print("3.")
  print("4.")
  print("5.")

从类主归档文件继续

  block1 = input()
  while block1 == ("a")
    print("Stored Data is shown below.")
    return sec
    time.sleep(1)
    secrets()
   while block1 == ("b")
    print("Stored Data is shown below.")
    return pro
    time.sleep(1)

2 个答案:

答案 0 :(得分:0)

time.sleep(2)以及while block1 == ("b")while block1 == ("a")的缩进错误都在末尾缺少分号,并且while block1 == ("b")缩进不正确。

这是更正的代码:

import time
print("Welcome to Code Vault Abraxis")
time.sleep(1)

class Username:
  print()
  username1 = input("Username: ")
  username2 = ("AbraxisUser")

  while username1 != username2:
    time.sleep(1)
    print()
    username1 = input("Username does not exist. Username: ")

class Password:
  time.sleep(1)
  print()
  password1 = input("Password:  ")
  password2 = ("cats")

  while password1 != password2:
   time.sleep(1)
   print()
   password1 = input("Wrong Password! Try again. Password: ")

class Mainarchive:
  def secrets(sec):
    time.sleep(2)
    print("1.")
    print("2.")
    print("3.")
    print("4.")
    print("5.")
def projects(pro):
  time.sleep(2)
  print("1.")
  print("2.")
  print("3.")
  print("4.")
  print("5.")

  block1 = input()
  while block1 == "a":
    print("Stored Data is shown below.")
    return sec
    time.sleep(1)
    secrets()
  while block1 == "b":
    print("Stored Data is shown below.")
    return pro
    time.sleep(1)

答案 1 :(得分:0)

这里:

while password1 != password2:
 time.sleep(1)
 print()
 password1 = input("Wrong Password! Try again. Password: ")

在这里:

   while block1 == ("b")
    print("Stored Data is shown below.")
    return pro
    time.sleep(1)

您只有一个空格,所有其他行都有2个空格缩进。