0

Here is my code:

class car():
    #defines a car model,speed,condition, and if you want to repair
    def __init__(self,model,speed):
        self.model = model
        self.speed = speed
        
    
    def roar(str = "vrooooooom"):
        print(str)
    
    def condition():
        user = bool(input('Is the car broken? True or False\n'))
        if user == True:
            print("Find local repair shop")
        else:
            print("No damage")

    def repair():
        wheels = ['O','O','O','O']
        if super().condition() == True:
            choice = input('Which one? 1-4\n')
            wheels[choice] = 'X'

When I call class.condition and put in False, I get 'find local repair shop' even though I want "no damage". As for repair, I feel like I'm using super() wrong.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Welcome to Stack Overflow. There are many things wrong with the code, all of which are common problems. I will try to link duplicates for all of them, starting with what you actually asked about. – Karl Knechtel Jul 09 '21 at 03:28
  • `super` is used for superclasses. Your class does not have a (nontrivial) superclass, so the work `super` likely shouldn't appear at all in your class. – Silvio Mayolo Jul 09 '21 at 03:29
  • "As for repair, I feel like I'm using super() wrong." I don't understand what you think it is supposed to be for at all; but this is something you should address by *reading a tutorial* rather than trying to ask for help on Stack Overflow. This is *not a discussion forum*, so questions should be primarily about fixing something, not about understanding something. – Karl Knechtel Jul 09 '21 at 03:33

1 Answers1

2

That's not how it works. According to this post, Python considers any non-empty string as True. So when you enter False, it becomes a non-empty string which evaluates to True:

Instead, you should do this.

def condition():
    user = input('Is the car broken? True or False\n')
    if user == 'True':
        print("Find local repair shop")
    else:
        print("No damage")
  • Any time you are linking another Stack Overflow post where the answers there are already sufficient to answer OP's question, that makes the question a *duplicate* that should be marked as such, rather than answered yourself. – Karl Knechtel Jul 09 '21 at 03:31
  • Ok @KarlKnechtel, I will keep that in mind –  Jul 09 '21 at 03:32