Почему Python 3 выдает ошибку вкладки, когда, по-видимому, ее нет? - PullRequest
0 голосов
/ 03 июля 2019

Я пишу игру на Python, и в ней говорится, что есть странное использование пробелов и отступов. Я не знаю почему, так как мне это кажется вполне нормальным. Почему это не работает?

import random
import time
from time import sleep
import sys

class Stats:
    def __init__(self, hunger, dehydration, phys_strength, mental_strength, psychic_powers, intelligence):
        self.hunger = hunger
        self.dehydration = dehydration
        self.phys_strength = phys_strength
        self.mental_strength = mental_strength
        self.psychic_powers = psychic_powers
        self.intelligence = intelligence

hero_stats = Stats(10, 10, 10, 20, 0, 20)

hunger_info = f"Your hunger level is {hero_stats.hunger}. Your stomach is full when you are at 0, and you starve at 100."


def user_input(input1):
    if input1.lower() == "hunger info":
        printfast("\n")
        printfast(hunger_info)

Ошибка:

Python Files xxxxxxxxxxxxxx$ python3 adventuregame.py
  File "adventuregame.py", line 36
    printfast(hunger_info)
                         ^
TabError: inconsistent use of tabs and spaces in indentation
xxxxxxx-Air:Python Files xxxxxxxxxxxxxx$

1 Ответ

0 голосов
/ 03 июля 2019

Перед предыдущей строкой printfast("\n") есть вкладка, а оставшаяся часть отступа сделана с пробелами.

Вы всегда должны использовать редактор, который преобразует вкладки в 4 пробела.

...