Код строки, который я написал, помечен как «неопределяемый не соответствует ни одному внешнему уровню отступа», почему это так? - PullRequest
0 голосов
/ 09 марта 2020

Блок кода ниже для контекста.

import requests
from termcolor import colored
import time
import replit
from time import sleep
import random
from random import seed
from random import randint
import sys

task1 = 0
task2 = 0
task3 = 0
task4 = 0
task5 = 0
task6 = 0
task7 = 0
task8 = 0
task9 = 0
task10 = 0
logout = 0

def mainterminal():
  print(colored("\n 1) Tasks \n 2) Device Management \n 3) Creature Information \n 4) Logoff", "white"))
  mtchoice = input()
  if mtchoice == "1":
   taskterminal()

def taskterminal():
  global task1
  global task2
  global task3
  global task4
  global task5
  global task6
  global task7
  global task8
  global task9
  global task10
  global logout
  print(colored("\n 1) Print Posters \n 2) Print Flyers \n 3) Wash Dishes \n 4) Clean Tables \n 5) Analyze Daily Revenue \n 6) Create New Playlist \n 7) Purchase Balloons \n 8) Purchase Paper Cups \n 9) Clean Stage \n 10) Refill Coffee \n 11) Return to main terminal", "white"))
  tchoice = input()
  if tchoice == "1":
   if task1 < 1:
    typer(colored("Printing Posters.", "blue"))
    print("")
    typer(colored("..........", "blue"))
    task1 = 0 + 1
    logout = 0 + 0.1 
    print(task1)
    print(logout)
    taskterminal()
  else:
   return(colored("Task is already completed", "red"))
   taskterminal()

 elif tchoice == "2":
   if task2 < 2:
    typer(colored("Printing Flyers.", "blue"))
    print("")
    typer(colored("..........", "blue"))
    task2 = 0 + 1
    logout = 0 + 0.1 
    print(task2)
    print(logout)
    taskterminal()
  else:
   return(colored("Task is already completed", "red"))
   taskterminal()
 elif tchoice == "11":
   replit.clear()
   mainterminal()


def typer(words):
  for char in words:
        time.sleep(0.05)
        sys.stdout.write(char)
        sys.stdout.flush()

def typertask(words):
  for char in words:
        time.sleep(2)
        sys.stdout.write(char)
        sys.stdout.flush()

def typerslow(words):
  for char in words:
        time.sleep(1.5)
        sys.stdout.write(char)
        sys.stdout.flush()

Это должно работать, но когда я его запускаю, я получаю этот код ошибки

    elif tchoice == "2":
                       ^
IndentationError: unindent does not match any outer indentation level

Часть, которая говорит если tchoice == "1": не дает код ошибки, поэтому я не понимаю, почему, когда вы меняете его на elif tchoice == "2": , он дает код ошибки.

Помощь?

Я дам больше частей кода, если вам понадобится помощь.

Ответы [ 2 ]

1 голос
/ 09 марта 2020

Отступы были неправильными во многих частях кода:

import requests
from termcolor import colored
import time
import replit
from time import sleep
import random
from random import seed
from random import randint
import sys

task1 = 0
task2 = 0
task3 = 0
task4 = 0
task5 = 0
task6 = 0
task7 = 0
task8 = 0
task9 = 0
task10 = 0
logout = 0

def mainterminal():
    print(colored("\n 1) Tasks \n 2) Device Management \n 3) Creature Information \n 4) Logoff", "white"))
    mtchoice = input()
    if mtchoice == "1":
        taskterminal()

def taskterminal():
    global task1
    global task2
    global task3
    global task4
    global task5
    global task6
    global task7
    global task8
    global task9
    global task10
    global logout
    print(colored("\n 1) Print Posters \n 2) Print Flyers \n 3) Wash Dishes \n 4) Clean Tables \n 5) Analyze Daily Revenue \n 6) Create New Playlist \n 7) Purchase Balloons \n 8) Purchase Paper Cups \n 9) Clean Stage \n 10) Refill Coffee \n 11) Return to main terminal", "white"))
    tchoice = input()
    if tchoice == "1":
        if task1 < 1:
            typer(colored("Printing Posters.", "blue"))
            print("")
            typer(colored("..........", "blue"))
            task1 = 0 + 1
            logout = 0 + 0.1 
            print(task1)
            print(logout)
            taskterminal()
        else:
            return(colored("Task is already completed", "red"))
            taskterminal()

    elif tchoice == "2":
        if task2 < 2:
            typer(colored("Printing Flyers.", "blue"))
            print("")
            typer(colored("..........", "blue"))
            task2 = 0 + 1
            logout = 0 + 0.1 
            print(task2)
            print(logout)
            taskterminal()
        else:
            return(colored("Task is already completed", "red"))
            taskterminal()

    elif tchoice == "11":
        replit.clear()
        mainterminal()


def typer(words):
    for char in words:
        time.sleep(0.05)
        sys.stdout.write(char)
        sys.stdout.flush()

def typertask(words):
    for char in words:
        time.sleep(2)
        sys.stdout.write(char)
        sys.stdout.flush()

def typerslow(words):
    for char in words:
        time.sleep(1.5)
        sys.stdout.write(char)
        sys.stdout.flush()

Попробуйте это и дайте мне знать, если есть проблема. Мой совет для вас - использовать текстовый редактор или блокнот jupyter, который облегчает разрешение проблем, связанных с синтаксисом.

0 голосов
/ 09 марта 2020

В коде есть проблема с отступами, я вижу, что у вас смешанные пробелы, если вы заблокировали блок, исправили его, отлично работают на моей IDE (pyCharm), вы также можете использовать Sublime Text 3, его полезный инструмент для проверки отступов. Вы можете также используйте Вид> Отступ> Намерение, используя пробелы.

import requests
from termcolor import colored
import time
import replit
from time import sleep
import random
from random import seed
from random import randint
import sys

task1 = 0
task2 = 0
task3 = 0
task4 = 0
task5 = 0
task6 = 0
task7 = 0
task8 = 0
task9 = 0
task10 = 0
logout = 0

def mainterminal():
  print(colored("\n 1) Tasks \n 2) Device Management \n 3) Creature Information \n 4) Logoff", "white"))
  mtchoice = input()
  if mtchoice == "1":
   taskterminal()

def taskterminal():
  global task1
  global task2
  global task3
  global task4
  global task5
  global task6
  global task7
  global task8
  global task9
  global task10
  global logout
  print(colored("\n 1) Print Posters \n 2) Print Flyers \n 3) Wash Dishes \n 4) Clean Tables \n 5) Analyze Daily Revenue \n 6) Create New Playlist \n 7) Purchase Balloons \n 8) Purchase Paper Cups \n 9) Clean Stage \n 10) Refill Coffee \n 11) Return to main terminal", "white"))
  tchoice = input()
  if tchoice == "1":
   if task1 < 1:
    typer(colored("Printing Posters.", "blue"))
    print("")
    typer(colored("..........", "blue"))
    task1 = 0 + 1
    logout = 0 + 0.1
    print(task1)
    print(logout)
    taskterminal()
   else:
    return colored("Task is already completed", "red")
    taskterminal()
  elif tchoice == "2":
   if task2 < 2:
    typer(colored("Printing Flyers.", "blue"))
    print("")
    typer(colored("..........", "blue"))
    task2 = 0 + 1
    logout = 0 + 0.1
    print(task2)
    print(logout)
    taskterminal()
   else:
    return(colored("Task is already completed", "red"))
    taskterminal()
  elif tchoice == "11":
   replit.clear()
   mainterminal()


def typer(words):
  for char in words:
        time.sleep(0.05)
        sys.stdout.write(char)
        sys.stdout.flush()

def typertask(words):
  for char in words:
        time.sleep(2)
        sys.stdout.write(char)
        sys.stdout.flush()

def typerslow(words):
  for char in words:
        time.sleep(1.5)
        sys.stdout.write(char)
        sys.stdout.flush()
...