inconsistent use of tabs and spaces in indentation

0 votes

I have been  trying to create an application in Python 3.2 and by using all tabs all the time for indentation, I noticed that even the editor changes some of them into spaces and then prints out "inconsistent use of tabs and spaces in indentation" when I try to run the program. How could I change the spaces into tabs? As I am new to programming, I would be glad if I could get some overall tips on my code. If I have made a lot of mistakes I would be happy to hear. Have shared my code below:-



import random 


attraktioner = ["frittfall","bergodalbana","spökhuset"] 



class Nojesfalt: 
      def __init__(self, attraktion): 
            self.val = attraktion 
            self.langd = 0 
            self.alder = 0 


#längdgräns för fritt fall 
      def langdgrans(self): 
            print("") 
            self.langd = int(input("Hur lång är du i cm? ")) 
            if self.langd < 140: 
                  print("tyvärr, du är för kort, prova något annat") 
                  return 0 
            elif self.langd >= 140: 
                  print("håll dig hatten, nu åker vi!") 
                  print(" ") 
                  return 1 



#åldersgräns för spökhuset 
      def aldersgrans(self): 
            print("") 
            self.alder = int(input("Hur gammal är du? ")) 
            if self.alder < 10: 
                print("tyvärr, du är för ung, prova något annat") 
                return 0 
          elif self.alder >= 10: 
                print("Gå in om du törs!") 
                print(" ") return 1 


#åker attraktion frittfall lr bergodalbana 
            def aka(self): 
                        print("") 
            print(self.val) 
            tal = random.randint(0,100) 
            if tal < 20: 
                print("åkturen gick åt skogen, bättre lycka nästa gång") 
            elif tal >= 20: 
                print("jabbadabbbadoooooooo") 
                return 1 





#går i spökhuset 
            def aka1(self): 
                          print("") 
            print(self.val) 
            tal = random.randint(0,100)
            if tal < 20: 
                print("du är omringad av spöken och kan inte fortsätta") return 0 
            elif tal >= 20: 
                  print("Buhuuuuuu, buuuhuuuu") 
                  return 1 

#programkod 
print("Välkommen till nöjesfältet, vad vill du göra?") 
print(" ") 


while 1: 
      vald_attr = input("Vad vill du göra?\n1. frittfall\n2. bergodalbana\n3. spökhuset\n4. Avsluta\n")                                  if vald_attr == "1": 
      val= Nojesfalt(attraktioner[0]) 
      if val.langdgrans() == 1: 
        val.aka() 
elif vald_attr == "2":
    val = Nojesfalt(attraktioner[1]) val.aka()
elif vald_attr == "3": 
      val = Nojesfalt(attraktioner[2]) 
      if val.aldersgrans() == 1: 
          val.aka1() 
elif vald_attr == "4": 
    break
Feb 10, 2022 in Python by Soham
• 9,700 points
1,439 views

1 answer to this question.

0 votes
To answer your question, start with eliminating the use of tabs. After which, set your editor to use 4 spaces for indentation. Then do a search and replace all tabs with 4 spaces. You should make sure your editor is set to display tabs as 8 spaces. Please remember that the  reason for 8 spaces for tabs is because you immediately notice when tabs have been inserted unintentionally - such as when copying and pasting from example code that uses tabs rather than spaces.
answered Feb 10, 2022 by Rahul
• 9,670 points

Related Questions In Python

0 votes
0 answers

what is the use of args and kwargs in python?

can you an example for each? READ MORE

May 11, 2019 in Python by Waseem
• 4,540 points
582 views
0 votes
0 answers

Use and meaning of "in" in an if statement?

In an example from Zed Shaw's Learn Python ...READ MORE

Apr 22, 2022 in Python by Edureka
• 13,620 points
249 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
4,242 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
0 votes
2 answers

What's the difference between %s and %d in Python string formatting?

The reason is that they are using ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,670 points
19,870 views
0 votes
1 answer

Reverse a string in Python

You should try to use the following ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,670 points
478 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP