1

How can i make so, that user uses input() method for giving a value for argument wheels, to the class Car?:

class Car(object):
    def __init__(self, name, wheels):
        self.name = name
        self.wheels = wheels
first_car = Car()
ufo
  • 359
  • 1
  • 5
  • 11

1 Answers1

0

get the input from the user, pass it to the car

class Car(object):
    def __init__(self, name):
        self.name = name
    ... etc etc

user_name = input("What name do you want?")
first_car = Car(user_name)

edit: You can also call the input() from inside the class:

class Car(object):
   def __init__(self):
       self.name = input("What name do you want")

first_car = Car()
Matthew
  • 672
  • 4
  • 11
  • A better method would be to separate the input into a class method - see e.g. http://stackoverflow.com/q/24986072/3001761 – jonrsharpe May 02 '15 at 13:28
  • @jonrsharpe yes, that it would (added to my answer). @ ufo: protip, you can accept answers to mark the question as answered by checking the green check mark. – Matthew May 02 '15 at 13:31