This question already has answers here:
Asking the user for input until they give a valid response
(22 answers)
Closed 8 years ago.
I'm making a pizza operator program for school. what is basically does is it asks for the customers name, asks if you want pickup or delivery etc. The problems I have encountered is that when I don't type anything into the input it will give the error to make you input it but then will automatically stop the program. I would like it to repeat itself. and also I have a bug in get_user_info when I click 1, 2 or 3 it does nothing but go in a infinite loop which I cannot seem to solve. I hope you guys could help me thank you very much in advance.
Regards,
Johnathon
My code
premium_pizzas = ["Supreme Cheese", "The Legendary pizza", "Pentakill supreme", "Teeto shroomo supreme", "The volcanic rengar", "Cheese and Ham" , "Vegetriano" ]
gourmet_pizzas = ["Flame Gorrila", "Snazzy chicken", "Intergalactic BBQ", "BBQ Chicken"]
#premium_pizzas = 8.50
#gourmet_pizzas = 5.00
customer_name = ""
def get_customer_name():
customer_name =input("what is your name?\n\t")
if customer_name is "":
print("Error please enter a name!\n\t")
#else: get_user_info()
def get_delivery_details():
get_address = input("Please enter a delivery address\n\t:")
if get_address == "":
print("error you must enter a address")
get_phone_number = str(input("please enter your phone number"))
if get_phone_number is "":
print("Input must be an integer(numbers only)")
if get_phone_number is "abcdefghijklmnopqrstuvwxyz":
print("Input must be an integer(numbers only)")
else:
get_pizza_list()
def get_pizza_list():
for i in range (0,6):
None
def get_user_info():
while not get_user_info == "0":
user_input=str(input("Press 1 for delivery press\nPress 2 for pickup\nPress 3 to exit\n\t:"))
if get_user_info == "1":
get_delivery_details()
elif get_user_info == "2":
get_pizza_list()
elif get_user_info == "3":
exit
#get_user_info()
get_customer_name
#get_delivery_details()
#get_pizza_list()
You want to loop as long as the customer name is empty:
customer_name = ""
def get_customer_name():
while (customer_name == ''):
customer_name = raw_input("what is your name?\n\t")
if customer_name is "":
print("Error please enter a name!\n\t")
In addition, I would re-think the use of global variables. Programs using globals do not scale well.
def get_customer_name():
result = ''
while (result is ''):
result = raw_input("what is your name?\n\t")
if (result is ''):
print("Error please enter a name!\n\t")
return(result)
and later in the program:
customer_name = get_customer_name()
The first problem:
I would change
customer_name =input("what is your name?\n\t")
if customer_name is "":
print("Error please enter a name!\n\t")
with
customer_name=""
while customer_name == "":
customer_name =input("what is your name?\n\t")
print("Error please enter a name!\n\t")
And the other problem... quick suggestion: are you sure you wanna read user_input and use get_user_info as a variable? Just use user_input, not the name of the function :) ^^
Editing so not to pollute the edit place:
while not user_input == "3":
user_input=str(input("Press 1 for delivery press\nPress 2 for pickup\nPress 3 to exit\n\t:"))
if user_input == "1":
get_delivery_details()
else user_input == "2":
get_pizza_list()
Basically you cycle until user_input is different from 3, the (main) problem with your solution was that you were using a bogus variable (get_user_info) to perform the check to let the cycle end, BUT you were setting a different one (user_input) ;)
1. Use raw_input()
2. Work with objects/classes. It'll make your program more readable/debugable/organized.
3. Some of your if statements could be rewritten.
4. Make global variables uppercase for readability. (actually not sure if this in PEP-8 but I always do it)
Example
Here is something I made. It is dirty but it works.
PREMIUM_PIZZAS = ["Supreme Cheese", "The Legendary pizza", "Pentakill supreme", "Teeto shroomo supreme", "The volcanic rengar", "Cheese and Ham" , "Vegetriano" ]
GOURMET_PIZZAS = ["Flame Gorrila", "Snazzy chicken", "Intergalactic BBQ", "BBQ Chicken"]
class Customer():
def __init__(self):
self.name = ''
self.address = ''
self.phone = ''
self.pickup = False
self.pizza = ''
class Order():
def __init__(self):
self._customer = Customer()
def get_order(self):
if not self.get_customer_name():
return None
if not self.get_user_info():
return None
return self._customer
def get_customer_name(self):
name = raw_input("what is your name?\n\t")
if not name:
print("Please enter a name!\n\t")
else:
self._customer.name = name
return True
def get_delivery_details(self):
address = raw_input("Please enter a delivery address\n\t:")
if not address:
print("You must enter a address")
return None
self._customer.address = address
phone_number = raw_input("Please enter your phone number\n\t")
try:
self._customer.phone = int(phone_number)
except:
print("Input must be an integer(numbers only)")
return None
pizza_choice = self.get_pizza_list()
if not pizza_choice:
return None
return True
def get_pizza_list(self):
# if anything went wrong, return None
# get a listing of the pizzas here, etc
choice = PREMIUM_PIZZAS[1]
if choice:
self._customer.pizza = choice
return True
def get_user_info(self):
user_choice = raw_input("Press 1 for delivery press\nPress 2 for pickup\nPress 3 to exit\n\t:")
if user_choice == "1":
if self.get_delivery_details():
return True
elif user_choice == "2":
self._customer.pickup = True
if self.get_pizza_list():
return True
while True:
print '--\nWelcome, please order a pizza!'
order = Order()
info = order.get_order()
print '--'
if info:
for attr in [a for a in dir(info) if not a.startswith('__')]:
print '%s: %s' % (attr ,getattr(info, attr))
Output
dsc:~/bla$ python test.py
--
Welcome, please order a pizza!
what is your name?
Sander Ferdinand
Press 1 for delivery press
Press 2 for pickup
Press 3 to exit
:1
Please enter a delivery address
:The Netherlands
Please enter your phone number
8349644343
--
address: The Netherlands
name: Sander Ferdinand
phone: 8349644343
pickup: False
pizza: The Legendary pizza
--
Welcome, please order a pizza!
what is your name?
You might want to use my snippet as an example for making a class that contains all the pizzas and their individual prizes and implement that in!
Related
New to programming and trying to learn how to store data using pickle. Essentially, what I'm trying to do is create an address book using classes stored in a dictionary. I define the class (Contact). It all worked, but when I tried to introduce pickling to store data from a previous session, I've created 2 errors that I've found so far.
1: If I select to load a previous address book, I cant update or view the class variables. It's almost like there are two different dictionaries.
2: I select not to load a previous address book and add a contact. When I add the contact and try to view the contacts, I'll get an "Unbound Error: local variable 'address book' referenced before assignment"
What am I doing wrong with pickling?
address_book= {}
class Contact:
def __init__(self,first_name,last_name, phone,company):
self.first_name = first_name
self.last_name = last_name
self.phone = phone
self.company = company
def __call__(self):
print("Contact: %s \nPhone #: %s \nCompany: %s" %(self.name,self.phone,self.company))
def erase(entry):
del address_book[entry] # delete address book entry
del entry #delete class instance
def save():
new_file = open("addressBook.pkl", "wb")
saved_address = pickle.dump(address_book, new_file)
new_file.close()
def load():
open_file = open("addressBook.pkl", "rb")
address_book = pickle.load(open_file)
open_file.close()
print(address_book)
return address_book
def add_contact():
first_name = input("Please type the first name of the contact. ")
last_name = input("Please type in the last name of the contact. ")
if " " in first_name or " " in last_name:
print("Please do not add spaces to your first or last name.")
else:
phone = input("Please type the user phone number without hyphens. ")
if not phone.isnumeric():
print("That isn't a valid phone number.")
else:
company = input("Please type the company they work for. ")
contact = Contact(first_name,last_name,phone,company)
address_book[first_name + " " +last_name] = contact #assign key[first and last name] to value[the class instance] in dictionary
def view_contact(entry):
if entry in address_book:
print("First Name: %s" %(address_book[entry].first_name)) #get class variables
print("Last Name: %s" %(address_book[entry].last_name))
print("Phone Number: %s" %(address_book[entry].phone))
print("Company: %s" %(address_book[entry].company))
else:
print("That person isn't in your address book")
def update(entry):
if entry in address_book:
update_choice = input("Would you like to update the first name (f), last name (l), phone (p), or company (c)? ").lower()
if update_choice == "f":
address_book[entry].first_name = input("Please type the updated first name of this contact. ")
updated_key = address_book[entry].first_name + " " + address_book[entry].last_name
address_book[updated_key] = address_book[entry]
del address_book[entry] #delete old key
elif update_choice == "l": #update last name
address_book[entry].last_name = input("Please type the updated last name of this contact. ")
updated_key = address_book[entry].first_name + " " + address_book[entry].last_name
address_book[updated_key] = address_book[entry]
del address_book[entry]
elif update_choice == "p":
address_book[entry].phone = input("Please type the updated phone number of this contact. ")
elif update_choice == "c":
address_book[entry].company = input("Please type the updated company of this contact. ")
else:
print("That was not valid. Please try again.")
def main():
print("Welcome to your address book!!")
returning_user = input("Would you like to load a previous address book? Y or N ").lower()
if returning_user == "y":
address_book = load()
while True:
choice = input("Please type A:Add, B:View All Contacts, V:View a Contact, D:Delete, U:Update, or X:Exit ").lower()
if choice == "x":
break
elif choice == "a":
add_contact()
elif choice == "b":
if len(address_book) == 0: #error check if no contacts
print("You don't have any friends. PLease go make some and try again later. :(")
else:
for i in address_book:
print(i)
elif choice == "v":
if len(address_book) == 0:
print("You don't have any friends. PLease go make some and try again later. :(")
else:
view = input("Who do you want to view? Please type in their first and last name. ")
view_contact(view)
elif choice == "d":
if len(address_book) == 0:
print("You don't have any friends. PLease go make some and try again later. :(")
else:
contact = input("Please type the first and last name of the person you want to delete ")
if contact in address_book:
erase(contact)
elif choice == "u":
if len(address_book) == 0:
print ("C'mon, you don't know anyone yet. How about you make some friends first?")
else:
choice = input("What is the first and last name of the person you'd like to update? ")
update(choice)
else:
print("That was not valid. Please try again.")
print()
save_book = input("Would you like to save your book? Y or N ").lower()
if save_book == "y":
save()
print("Thanks for using the address book!")
main()
Hopefully my code and question(s) are clear for understanding. If they are not please provide feed back.
I am fairly new to programing/coding so I decided to develop a program using Python that acts like a pizza ordering system. I eventually would like to use this code to develop a website using Django or Flask.
I have just finished the first step of this program where I am asking the user if this will be for delivery of pickup. Depending on what the user chooses the program will ask for specific information.
The area I feel like I am struggling with the most is developing classes and functions. specifically taking a variables from one function and using that variable in another function. I posted a past example of my code and I was advised that Global variables are not good to use in code. So I am trying really hard to refrain from using them.
Here is the code for reference:
import re
running = True
class PizzaOrderingSys():
"""order a customized pizza for take out or delivery """
def delivery_or_pickup(self): # Is the order for devilery or pickup?
print("\nWill this order be for pickup or delivery?")
self.delivery = input("P - pick up / D - delivery : ")
self.delivery = self.delivery.title()
if self.delivery == "D":
while running == True:
customerName = input("\nName for the order: ")
if not re.match("^[a-zA-Z ]*$", customerName):
print("Please use letters only")
elif len(customerName) == 0:
print("Please enter a vaild input")
else:
customerName = customerName.title()
break
while running == True:
customerPhoneNumber = input("\nEnter a phone number we can contact you at: ")
if not re.match("^[0-9 ]*$", customerPhoneNumber):
print("Please use numbers only")
elif len(customerPhoneNumber) == 0:
print("Please enter a a contact phone number")
else:
break
while running == True:
house_num = input("\nWhat is your house or unit number: ")
if not re.match("^[0-9 /]*$", house_num):
print("Please use numbers only")
elif len(house_num) == 0:
print("Please enter a valid input ")
else:
break
while running == True:
streetName = input("\nStreet name: ")
if not re.match("^[a-zA-Z ]*$", streetName):
print('Please use letters only.')
elif len(streetName) == 0:
print("Please enter a valid input")
else:
streetName = streetName.title()
break
while running == True:
city = input("\nCity: ")
if not re.match("^[a-zA-Z ]*$", city):
print("Please use letters only")
elif len(city) == 0:
print("Please enter a valid input")
else:
city = city.title()
break
while running == True:
zip_code = input("\nZip Code:")
if not re.match("^[0-9 /]*$", zip_code):
print("Please use numbers only")
elif len(zip_code) == 0 or len(zip_code) > 5:
print("Please enter a valid input")
else:
break
elif self.delivery == "P":
while running == True:
customerName = input("\nName for the order: ")
if not re.match("^[a-zA-Z ]*$", customerName):
print("Please use letters only")
elif len(customerName) == 0:
print("Please enter a valid input")
else:
customerName = customerName.title()
break
while running == True:
customerPhoneNumber = input("\nEnter a phone number we can contact you at: ")
if not re.match("^[0-9 ]*$", customerPhoneNumber):
print("Please use numbers only")
elif len(customerPhoneNumber) == 0:
print("Please enter a valid input")
else:
break
else:
print("Please enter P or D ")
delivery_or_pickup()
order = PizzaOrderingSys()
order.delivery_or_pickup()
My question is this: How would I use variables found in one function of my class and use it in another future function??
For example if I wanted to retrieve variables the functions customerName, customerPhoneNumber, house_num, streetName, city, Zip_code found in delivery_or_pick() function and use them in a function called:
def customer_receipt():
What would I need to do to my exiting code or to the def customer_receipt() function to obtain that information?
Any help with my questions or advise on any other area that stick out to you would be be greatly appropriated.
This is my second post on Stackoverflow so I apologize if what i am asking is unclear or the format of my question might is off, I am still learning.
Thank you again.
The idea here is that you can use your class variables to save data between method calls. Methods are functions that belong to a class. For example you could use Python's class initialization and create a dict of orders. Here is a simple example of such system, take a note of the usage of self keyword. self refers to the instance of the class and you can use it to access the variables or methods of the instance:
class PizzaOrderingSys:
def __init__(self):
# Initializing some class variables
self.running = True # Now you can use self.running instead of global running variable
self.orders = {}
def delivery_or_pickup(self):
# Somewhere at the end where you have collected the needed info
order = {
"zip_code": zip_code,
"city": city,
# You can enter all of the needed data similarly
}
order_id = "SomeIdHere" # ID could be anything, it just should be unique
self.orders[order_id] = order
return order_id
def customer_receipt(self, id):
# Now you can access all of the order here with self.orders
order = self.orders.get(id) # Select some specific order with id.
# Using get to avoid the situation
# where no orders or invalid id would raise an exception
if order:
receipt = f"Order {id}:\nCustomer city {order['city']}"
else:
receipt = None
return receipt
pizzasystem = PizzaOrderingSys()
order_id = pizzasystem.delivery_or_pickup()
receipt = pizzasystem.customer_receipt(order_id)
print(receipt)
# >>> Order 1235613:
# Customer city Atlantis
I recommend that you read more about classes, for example, python docs have great material about them.
I am fairly new to Python/programming, I started about four months ago and since I am a teacher and may possible have a lot more time on my hands.
For my first project I have started to develop a pizza ordering system-- at the moment I am just having the user interact with the program through the terminal. However, I plan to evidentially use Django to create a web page so a user can actually interact with.
I will first share my code:
import re
sizePrice = {
'small': 9.69,
'large': 12.29,
'extra large': 13.79,
'party size': 26.49 }
toppingList = [ 'Anchovies', 'Bacon', 'Bell Peppers', 'Black Olives',
'Chicken', 'Ground Beef', 'Jalapenos', 'Mushrooms',
'Pepperoni','Pineapple', 'Spinach']
pickupCost = 0 deliveryCost = 5.0
running = True
def pick_or_delivery():
global delivery
print('\nWill this be for pick up or delivery?')
delivery = input("P - pick up / D - delivery")
delivery = delivery.title() # changes the letter inputted to an upper case.
print(f'This order will be for {delivery}')
if delivery == "D":
while running == True:
global customerName
customerName = input("\nName for the order: ")
if not re.match("^[a-zA-Z ]*$", customerName):
print("Please use letters only")
elif len(customerName) == 0:
print("Please enter a vaild input")
else:
customerName = customerName.title()
break
while running == True:
global customerPhoneNumber
customerPhoneNumber = input("\nEnter a phone number we can contact you at: ")
if not re.match("^[0-9 ]*$", customerPhoneNumber):
print("Please use numbers only")
elif len(customerPhoneNumber) == 0:
print("Please enter a a contact phone number")
else:
break
while running == True:
global streetName
streetName = input("Street name: ")
if not re.match("^[a-zA-Z ]*$", streetName):
print('Please use letters only.')
elif len(streetName) == 0:
print("Please enter a valid input")
else:
streetName = streetName.title()
break
elif delivery == "P":
while running == True:
global customerName
customerName = input("\nName for the order: ")
if not re.match("^[a-zA-Z ]*$", customerName):
print("Please use letters only")
elif len(customerName) == 0:
print("Please enter a valid input")
else:
print("Please enter P or D")
customerName = customerName.title()
break
while running == True:
global customerPhoneNumber
customerPhoneNumber = input("\nEnter a phone number we can contact you at: ")
customerName = customerName.title()
if not re.match("^[0-9 ]*$", customer_telephone):
print("Please use numbers only")
elif len(customer_telephone) == 0:
print("Please enter a valid input")
else:
break
else:
print("Please enter P or D ")
pick_or_delivery()
pick_or_delivery()
When I run this code I receive the following:
SyntaxError: name 'customerName' is used prior to global declaration
I know the issue is in my global variables, however in my code I am placing the global variable before it is being called. So I am a little confused. Is the placement incorrect? If so, where should it go?
I think it is because you have globalised customerName within your if statements. Try and create a variable called customerName at the start of your function and give it a blank value, then globalise it at the start of your function.
print("Lets play a game")
print("You have to operte on some numbers")
print("Are you ready? , type yes or no ")
input = input().lower()
if input == "yes":
print("Ok now type your name and age (comma separated)")
name = input()
age = int(input())
if "\"" in name or ">" in name :
print("Use only alphanumeric characters")
else:
pass
if age <= 10 :
print("You cant play this game")
I keep on getting this error 'str' object is not callable in line 10.
You are shadowing the built-in input() function with the input variable, so the second time you call input() it tries to 'call' the string variable.
You will have to work out what to do when the user doesn't input what you expect, but here's a skeleton for what the code could look like:
print("Let's play a game")
print("You have to operate on some numbers")
text = input("Are you ready (yes/no)?").lower()
if text == "yes":
text = input("Enter your name and age (comma separated):")
fields = text.split(",")
if len(fields) != 2:
# Handle case of bad user input format
name = fields[0].trim()
if not all(c.isalpha() or c.isspace() for c in name):
# Handle case of bad entered name
try:
age = int(fields[1])
except ValueError:
# Handle case of bad entered age
if age <= 10:
print("You cannot play this game")
The problem you are getting derives from the name of the variable, "input". If you change it, "ready" in my example, you will avoid the error.
I would also recommend to include functions to check the inputs and use the while loop, so the program does not finish if there is an unexpected input.
Please, see my code below:
def check_predefined_input(variable, values, input_question, error_message, check = False):
variable = str(input(input_question))
try:
if(variable.lower() in values):
check = True
else:
raise Exception ("You have inserted an invalid option.")
except Exception as e:
print("ERROR: ", e)
print(error_message, "\n")
check = False
return variable, check
def check_string_input(variable, input_question, error_message, check = False):
variable = input(input_question)
if "\"" in variable or ">" in variable:
print("ERROR: ", error_message, "\n")
check = False
else:
check = True
return variable, check
def check_int_input(variable, input_question, error_message, check = False):
try:
variable = int(input(input_question))
check = True
except ValueError as ve:
print("ERROR: ", ve)
print(error_message, "\n")
variable = 0
check = False
return variable, check
print("Lets play a game")
print("You have to operate on some numbers")
ready_values = ["yes", "no"]
ready = ''
ready_input_question = "Are you ready? , type yes or no "
ready_error_message = "\tMake sure your answer is yes or not."
ready_check = False
while not ready_check:
ready, ready_check = check_predefined_input(ready, ready_values, ready_input_question, ready_error_message, ready_check)
if ready == "yes":
name = ""
name_check = False
name_input_question = "Ok now type your name: "
name_error_message = "Use only alphanumeric characters"
while not name_check:
name, name_check = check_string_input(name, name_input_question, name_error_message, name_check)
age = 0
age_check = False
age_input_question = 'Please, ' + name + ', insert your age: '
age_error_message = '\tMake sure you insert your age.\n\tDo not insert letters.'
while not age_check:
age, age_check= check_int_input(age, age_input_question, age_error_message)
if age <= 10 :
print("You cannot play this game")
else:
print("You are ready to play")
I want to user to input information and print out the total list. However, when the user input another list it only prints out the first list. How can I make the program print the users total input. Here's my code.
listing = []
class Car:
def __init__(self, ownerName=None, model=None, make=None, price=None):
self.ownerName = ownerName
self.model = model
self.make = make
self.price = price
def input(self):
print "Please update car info \n"
while True:
i = 0
listing.append(Car(raw_input("Owner Name"), raw_input("Model?"), raw_input("Make?"), raw_input("Price?")))
print "Updated"
print listing[i].ownerName, listing[i].model, listing[i].make, listing[i].price
addOn = raw_input("Continue? (Y/N)")
if addOn.lower() == "y":
i += 1
continue
else:
break
# search a car and print its information. Exit when user input is 'exit'
def menu():
x = Car()
print "PLease choose an option (1-4):\n"
choice = raw_input("1) input\n" \
"2) change price and owner\n" \
"3) search a car and print info\n" \
"\"exit\" Exit")
if choice == "1":
x.input()
elif choice == "2":
print "Price"
elif choice == "3":
print "Search and Print info"
menu()
#mhawke's answer should fix your problem. However, I do not like the idea of creating objects of a class from one of its functions. Check the edited code below.
listing = []
class Car:
def __init__(self, ownerName=None, model=None, make=None, price=None):
self.ownerName = ownerName
self.model = model
self.make = make
self.price = price
def input_car():
print "Please update car info \n"
i = 0
while True:
listing.append(Car(raw_input("Owner Name"), raw_input("Model?"), raw_input("Make?"), raw_input("Price?")))
print "Updated"
print listing[i].ownerName, listing[i].model, listing[i].make, listing[i].price
addOn = raw_input("Continue? (Y/N)")
if addOn.lower() == "y":
i += 1
continue
else:
break
# search a car and print its information. Exit when user input is 'exit'
def menu():
#x = Car()
print "PLease choose an option (1-4):\n"
choice = raw_input("1) input\n" \
"2) change price and owner\n" \
"3) search a car and print info\n" \
"\"exit\" Exit")
if choice == "1":
input_car()
elif choice == "2":
print "Price"
elif choice == "3":
print "Search and Print info"
menu()
I cleaned up the code a little bit. I should work now. Option 3 gives you a complete listing of all cars so far, so youhave an example to build on.
listing = []
class Car:
def __init__(self, ownerName=None, model=None, make=None, price=None):
self.ownerName = ownerName
self.model = model
self.make = make
self.price = price
#to have a useful method for our example I overwrite the __str__ method from object
def __str__(self):
return ",".join([self.ownerName, self.model, self.make, self.price])
#input does not handle aspects of car, therefore it should be not a method of car
def input():
print "Please update car info \n"
while True:
# there is no need for 'i' so I removed it
car = Car(raw_input("Owner Name"),
raw_input("Model?"),
raw_input("Make?"),
raw_input("Price?"))
listing.append(car)
print "Updated"
print car #possible since __str__ is overwritten
addOn = raw_input("Continue? (Y/N)")
if addOn.lower() == "n":
break
def menu():
keep_running = True
#added a while loop so the user stays in the program until he types 'exit'
#changed option '3' to have a working example to build on
while keep_running:
print "PLease choose an option (1-4):\n"
choice = raw_input("1) input\n" \
"2) change price and owner\n" \
"3) list all cars\n" \
"\"exit\" Exit")
if choice == "1":
input()
elif choice == "2":
print "Price"
elif choice == "3":
print "\n".join(map(str, listing))
elif choice == "exit":
keep_running = False
menu()
That's because you reset i on each iteration of your while loop.
Move the line:
i = 0
to the line before the while True:
That should fix the immediate problem, however, your code uses an unusual design. You should not create a Car object in order to create further instances of Cars which are then inserted into a global list.
At a minimum you could make input() a static method and have it return a list of Car instances to the caller. Then you can do away with the global listing variable. Also, you don't actually need to keep a counter in i you can just use -1 as the subscript to access the last item in the list:
#staticmethod
def input(listing=None):
if listing is None:
listing = []
print "Please update car info \n"
while True:
listing.append(Car(raw_input("Owner Name"), raw_input("Model?"), raw_input("Make?"), raw_input("Price?")))
print "Updated"
print('{0.ownerName} {0.model} {0.make} {0.price}'.format(listing[-1]))
addOn = raw_input("Continue? (Y/N)")
if addOn.lower() != "y":
break
return listing
Using a static method is good here because input() is related to Car objects so it makes sense to package that function with the class.
Now you can call input() without creating an instance of a Car. In your menu() function remove the x = Car() and change x.input() to listing = Car.input(). Or, if you want to append to an existing "listing" list, call Car.input(listing) which will append new input to listing. You can then print the returned list to see all user input:
def menu():
print "PLease choose an option (1-4):\n"
choice = raw_input("1) input\n" \
"2) change price and owner\n" \
"3) search a car and print info\n" \
"\"exit\" Exit")
if choice == "1":
listing = Car.input()
# print out all user entered cars
for car in listing:
print('{0.ownerName} {0.model} {0.make} {0.price}'.format(car))
elif choice == "2":
print "Price"
elif choice == "3":
print "Search and Print info"