Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我的代码缩进不正确?_Python_Python 3.x_Indentation - Fatal编程技术网

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

Python 为什么我的代码缩进不正确?,python,python-3.x,indentation,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")

我的[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)

您在
时间段都有缩进错误。sleep(2)
以及
当block1==(“b”)
当block1==(“a”)
在末尾缺少分号,而
当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)
在这里:

在这里:

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

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

完整堆栈跟踪的确切错误是什么?这是准确的密码吗?有一些非常明显的缩进错误,例如
time.sleep(2)
def secrets(sec)处于相同的缩进位置:
在while行的末尾不需要一个:吗?而区块1==(“a”)和区块1==(“b”)?
   while block1 == ("b")
    print("Stored Data is shown below.")
    return pro
    time.sleep(1)