def main(): guitars = [] print("My guitars!") name = input("Name:") while name != "": year = int(input("Year:")) cost = float(input("Cost:$")) guitar_to_add = Guitar(name, year, cost) guitars.append(guitar_to_add) print(guitar_to_add, "added.") name = input("Name:") guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) if guitars: guitars.sort() print("These are my guitars:") for i, guitar in enumerate(guitars): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {0}: {1.name:>30} ({1.year}), worth ${1.cost:10,.2f}\ {2}".format(i + 1, guitar, vintage_string)) else: print("There are no guitars")
def main(): guitars = [] print("My guitars!") name = input("Name: ") while name == "": name = input("Name: ") year = input("Year: ") while year == "": year = input("Year: ") Cost = input("Cost: ") while Cost == "": Cost = input("Cost: ") add_guitars = Guitar(name, year, Cost) guitars.append(add_guitars) guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) guitars.sort() print("These are my guitars:") for i, guitar in enumerate(guitars): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {0}: {1.name:>30} ({1.year}), worth ${1.cost:10,.2f}\ {2}".format(i + 1, guitar, vintage_string))
def main(): """Get Guitar objects in list until blank entry """ guitars = [] name = input("Enter guitar name: ") while name != "": year = int(input("Year made: ")) cost = float(input("Cost: ")) next_guitar_add = Guitar(name, year, cost) guitars.append(next_guitar_add) print(next_guitar_add, "Added to Guitars") name = input("Enter guitar name: ") guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) guitars.append(Guitar("Fender Stratocaster", 2014, 765.40)) guitars.append(Guitar("Sampson Special A8", 1990, 2800.00)) print("My Guitars: ") if guitars is not None: for i in range(len(guitars)): over_50 = ("This is a Vintage Guitar" if guitars[i].is_vintage() else "") # Ternary operator print("Guitar {}: {:<20} ({}), Cost: $ {:10.2f} {}".format( i + 1, guitars[i].name, guitars[i].year, guitars[i].cost, over_50))
def main(): print("My guitars!") guitars = [] name = input("Name: ") while name != "": year = int(input("Year: ")) cost = int(input("Cost: $")) add_guitar = Guitar(name, year, cost) guitars.append(add_guitar) print("{} ({}) : ${:,.2f} added.".format(name, year, cost)) name = input("Name:") guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) # print(guitars) print("These are my guitars:") for i, guitar in enumerate(guitars): vintage_string = "(vintage)" if guitar.is_vintage(): print("Guitar {}: {:>20} ({}), worth ${:10,.2f} {}".format( i + 1, guitar.name, year, cost, vintage_string)) else: print("Guitar {}: {:>20} ({}), worth ${:10,.2f} is not vintage". format(i + 1, guitar.name, year, cost))
def main(): """Guitar program, using Guitar class.""" guitars = [] print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) guitar_to_add = Guitar(name, year, cost) guitars.append(guitar_to_add) print(guitar_to_add, "added.") name = input("Name: ") guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) if guitars: # lists, strings and other collections are False when empty, True when non-empty # In order for sorting to work on Guitar objects, # at least the __lt__ method must be defined in Guitar class #guitars.sort() print("These are my guitars:") for i, guitar in enumerate(guitars): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {0}: {1.name:>30} ({1.year}), worth ${1.cost:10,.2f}\ {2}".format(i + 1, guitar, vintage_string)) else: print("No guitars :( Quick, go and buy one!")
def __init__(self, **kwargs): """ Construct main app. """ super().__init__(**kwargs) # Basic data example - list of Guitar objects - could be loaded from a file or something self.guitars = [ Guitar("Gibson L-5 CES", 1922, 16035.40), Guitar("Line 6 JTV-59", 2010, 1512.9), Guitar("Ukelele", 2017, 99.95) ]
def main(): """Test program for Guitar objects """ guitars = [] guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) guitars.append(Guitar("Fender Stratocaster", 2014, 765.40)) guitars.append(Guitar("Sampson Special A8", 1990, 2800.00)) guitar_list_print(guitars)
def run_test(): name = "Gibson L-5 CES" year = 1922 cost = 16035.40 guitar = Guitar(name, year, cost) other = guitar("Another Guitar", 2012, 1512.9) print("{} get_age() - Expected {}. Got {}".format(guitar.name, 95, guitar.get_age())) print("{} get_age() - Expected {}. Got {}".format(other.name, 95, other.get_age())) print() print("{} is_vintage() - Expected {}. Got {}".format(guitar.name, True, guitar.is_vintage())) print("{} is_vintage() - Expected {}. Got {}".format(other.name, False, other.is_vintage()))
def main(): Gibson = Guitar("Gibson L-5 CES", 1922, 16035.40) guitars = [Gibson] for guitar in guitars: print(guitar) print("{} get_age() - Expected 98. Got {}".format(Gibson.name, Guitar.get_age(Gibson))) print("{} is_vintage() - Expected True. Got {}".format( Gibson.name, Gibson.is_vintage()))
def main(): list_of_guitars = [] print("My Guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) guitar_to_add = Guitar(name, year, cost) list_of_guitars.append(guitar_to_add) print(guitar_to_add, "added.\n") name = input("Name: ") # list_of_guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # list_of_guitars.append(Guitar("Fender Stratocaster", 2014, 765.40)) if list_of_guitars: print( "\nThese are mine, you are not allowed to touch. But you may look") for i, guitar in enumerate(list_of_guitars, 1): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {}: {} ({}), worth ${} {}".format( i, guitar.name, guitar.year, guitar.cost, vintage_string)) else: print("Why you no have guitar, go go go and get one!")
def main(): """Guitar program using Guitar class""" guitars = [] print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) added_guitar = Guitar(name, year, cost) guitars.append(added_guitar) print(added_guitar, "added.") name = input("Name: ") if guitars: guitars.sort() print("These are my guitars:") for i, guitar in enumerate(guitars, 1): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {}: {:>20} ({}), worth ${:10,.2f}" " {}".format(i, guitar.name, guitar.year, guitar.cost, vintage_string)) else: print("No guitars in collection")
def main(): guitars = [] print_statements = ["Name: ", "Year: ", "Cost: "] num_of_guitars = 0 # guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) while True: values = [] # With no checks for correct input, we can loop through all data. for statement in print_statements: user_input = input(statement) if not user_input: # Blank strings are considered false in boolean sense, thus simply. # Better to do it this was as well, considering if they make any entry blank it will end the loop. break values.append(user_input) if not user_input: # Added a second to break out of the while loop break guitars.append(Guitar(values[0], values[1], int(values[2]))) # Final print statement before list is displayed. print(guitars[num_of_guitars]) num_of_guitars += 1 print("These are my guitars:") for index, guitar in enumerate(guitars, 1): # Ternary operator used with this, a bit too cramped for my liking however. vintage_string = "(vintage)" if guitar.is_vintage() else "" print( "Guitar {}: {g.name} ({g.year}), worth $ {g.cost:,.2f} {}".format( index, vintage_string, g=guitar))
def main(): guitars = [] # guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) exit = "Q" name = input("Enter Name of guitar or Enter 'Q' to quit: ") while name != exit: year = int(input("Year: ")) price = float(input("Cost: $")) add_guitar = Guitar(name, year, price) guitars.append(add_guitar) print(add_guitar, "added.") name = input("Enter Name of guitar or Enter 'Q' to quit: ") if guitars: guitars.sort() for g, guitar in enumerate(guitars): vintage = "" if guitar.is_vintage(): vintage = "(vintage)" print( "Guitar {0}: {1.name:>30} ({1.year}), worth ${1.cost:10,.2f}{2}" .format(g + 1, guitar, vintage)) else: print("Ukulele doesn't count!")
def main(): print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) guitar_to_add = Guitar(name, year, cost) GUITAR_LIST.append(guitar_to_add) print(guitar_to_add, "added.") name = input("Name: ") ''' List test, uncomment if needed ''' # GUITAR_LIST.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # GUITAR_LIST.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) if GUITAR_LIST: GUITAR_LIST.sort() print("These are my guitars:") for i, guitar in enumerate(GUITAR_LIST): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {0}: {1.name:>30} ({1.year}), worth ${1.cost:10,.2f}\ {2}".format(i + 1, guitar, vintage_string)) else: print("No guitars :( Quick, go and buy one!")
def main(): """Guitar Listing Program""" my_guitar_list = [] print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: ")) my_guitar = Guitar(name, year, cost) print("Added: {}".format(my_guitar)) my_guitar_list.append(my_guitar) name = input("Name: ") # my_guitar_list.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # my_guitar_list.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) print("\nThese are my guitars:") for i, entry in enumerate(my_guitar_list, 1): vintage_string = " (Vintage)" if entry.is_vintage() else "" print("Guitar {}: {} ({}), worth ${:,.2f}{}".format( i, entry.name, entry.year, entry.cost, vintage_string))
def main(): my_guitar = Guitar("Gibson L-5 CES", 1922, 16035.40) print("{} get_age() - Expected 97. Got {}".format(my_guitar.name, my_guitar.get_age())) another_guitar = Guitar("Fender Stratocaster", 2014, 765.4) print("{} get_age() - Expected 5. Got {}".format(another_guitar.name, another_guitar.get_age())) print("{} is_vintage() - Expected True. Got {}".format( my_guitar.name, my_guitar.is_vintage())) print("{} is_vintage() - Expected False. Got {}".format( another_guitar.name, another_guitar.is_vintage()))
def main(): new_guitar = Guitar("Gibson L-5 CES", 1922, 16035.40) another_guitar = Guitar("Another Guitar", 2013) print("{} get_age() - Expected 98. Got {}".format(new_guitar.name, new_guitar.get_age())) print("{} get_age() - Expected 7. Got {}".format(another_guitar.name, another_guitar.get_age())) print("{} is_vintage - Expected True. Got {}".format( new_guitar.name, new_guitar.is_vintage())) print("{} is_vintage - Expected False. Got {}".format( another_guitar.name, another_guitar.is_vintage()))
def run_tests(): """Test guitar class works correctly""" guitar_1 = Guitar("Gibson L-5 CES", 1922, 16035.40) guitar_2 = Guitar("Another Guitar", 2013, 1512.9) print("{} get_age() - Expected {}. Got {}".format(guitar_1.name, 98, guitar_1.get_age())) print("{} get_age() - Expected {}. Got {}".format(guitar_2.name, 7, guitar_2.get_age())) print() print("{} is_vintage() - Expected {}. Got {}".format(guitar_1.name, True, guitar_1.is_vintage())) print("{} is_vintage() - Expected {}. Got {}".format(guitar_2.name, False, guitar_2.is_vintage()))
def main(): guitars = [] name = input('Name:') while name != '': year = int(input('Year:')) cost = int(input('Cost: $')) add_to_guitars = Guitar(name,year,cost) guitars.append(add_to_guitars) print('{} ({}) :{} added'.format(name,year,cost)) name = input('Name:') if guitars != '': print('There are my guitars:') for i, guitar in enumerate(guitars): vintage_string = "" if guitar.is_vintage(guitar.get_age()): vintage_string = "(vintage)" print("Guitar {}: {:>5} ({}), worth ${:10,.2f}{}".format(i + 1, guitar.name, guitar.year, guitar.cost, vintage_string)) else: print('No guitars are showed.')
def main(): print("My guitars!") print("To open list, enter nothing in the name") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) AddGuitars = Guitar(name, year, cost) list.append(AddGuitars) print(AddGuitars, "added.") name = input("Name: ") if list: list.sort() print("These are my guitars:") for i, guitar in enumerate(list): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {0}: {1} ({1}), worth ${1} {2}".format( i + 1, guitar, vintage_string)) else: print("No guitars")
def main(): print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) guitar_to_add = Guitar(name, year, cost) GUITAR_LIST.append(guitar_to_add) print(guitar_to_add, "added.") name = input("Name: ") if GUITAR_LIST: GUITAR_LIST.sort() print("These are my guitars:") for i, guitar in enumerate(GUITAR_LIST): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {0}: {1.name:>30} ({1.year}), worth ${1.cost:10,.2f}\ {2}".format(i + 1, guitar, vintage_string)) else: print("No guitars :( Quick, go and buy one!")
from Prac_06.guitar import Guitar guitar = Guitar("Gibson L-5 CES", 1922, 16035.40) guitar1 = Guitar("ye", 2001, 20) guitar.get_age() print(guitar.is_vintage())
from Prac_06.guitar import Guitar print('My guitars!') guitar_list = [] name = None while name != '': name = input('Name: ') if name == '': continue year = int(input('Year: ')) cost = float(input('Cost: $')) guitar = Guitar(name, year, cost) print(guitar) guitar_list.append(guitar) print('There are my guitars: ') for index, single_guitar in enumerate(guitar_list): print("Guitar {0:}: {1:>20} ({2:}, worth ${3:,} ({4:}))".format( index, single_guitar.name, single_guitar.year, single_guitar.cost, 'VINTAGE' if single_guitar.is_vantage() else ''))
from Prac_06.guitar import Guitar guitars = [] """ guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) """ print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = int(input("Cost: $")) guitars.append(Guitar(name, year, cost)) name = input("Name: ") print("These are my Guitars:") for i, guitar in enumerate(guitars, 1): vintage = "(Vintage)" if guitar.is_vintage() else "" print("Guitar {}: {} ({}), worth ${:,.2f} {}".format( i, guitar.name, guitar.year, guitar.cost, vintage))
from Prac_06.guitar import Guitar guitar_1 = Guitar("Gibson L-5 CES", 1922, 16035.40) guitar_2 = Guitar("Another Guitar", 2013) print("{} get_age() - Expected 98. Got {}".format(guitar_1.name, guitar_1.get_age())) print("{} get_age() - Expected 7. Got {}".format(guitar_2.name, guitar_2.get_age())) print("{} is_vintage() - Expected True. Got {}".format(guitar_1.name, guitar_1.is_vintage())) print("{} is_vintage() - Expected False. Got {}".format(guitar_2.name, guitar_2.is_vintage()))
from Prac_06.guitar import Guitar my_guitar = [] str1 = "" name = str(input("Name: ")) year = int(input("Year: ")) cost = float(input("Cost: ")) while name != "": print("{} ({}) : ${:,} added.".format(name, year, cost)) str1 = str1 + name + "," + str(year) + "," + str(cost) my_guitar.append(str1) name = str(input("Name: ")) if name == "": break year = int(input("Year: ")) cost = float(input("Cost: ")) for i in range(len(my_guitar)): guitar = my_guitar[i].split(",") guitar = Guitar(guitar[0], int(guitar[1]), guitar[2]) print("Guitar {}: {:>10} ({}), worth ${:>15}".format( i + 1, guitar.get_name(), guitar.get_year(), guitar.get_cost()), end="") guitar.get_age() if guitar.is_vintage() == True: print("(Vintage)", end="\n") else: print("", end="\n")
from Prac_06.guitar import Guitar guitars = [] print("My guitars!") name = input("Name: ") while name: year = int(input("Year: ")) cost = float(input("Cost: $")) guitars.append(Guitar(name, year, cost)) print("{} ({}) : ${:,.2f} added.".format(name, year, cost)) name = input("Name: ") guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # for testing purposes guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) # for testing purposes print() print("These are my guitars:") longest_name = "" for guitar in guitars: if len(guitar.name) > len(longest_name): longest_name = guitar.name for i, guitar in enumerate(guitars, 1): vintage_string = " (vintage)" if guitar.is_vintage() else "" print("Guitar {}: {:<{}} ({}), worth ${:10,.2f}{}".format( i, guitar.name, len(longest_name), guitar.year, guitar.cost,
from Prac_06.guitar import Guitar guitar_1 = Guitar("Gibson L-5 CES", 1922, 16035.40) another = Guitar("Line 6 JTV-59", 2010, 1512.9) print("{} get_age() - Expected 97. Got {}".format(guitar_1.name, guitar_1.get_age())) print("{} get_age() - Expected True. Got {}".format(guitar_1.name, guitar_1.is_vintage())) print("{} get_age() - Expected 9. Got {}".format(another.name, another.get_age())) print("{} get_age() - Expected False. Got {}".format(another.name, another.is_vintage()))
""" name = "Gibson L-5 CES" year = 1922 cost = 16035.40 """ from Prac_06.guitar import Guitar my_guitar = Guitar("Gibson L-5 CES", 1922, 16035.40) print(my_guitar) print(my_guitar.get_age()) print(my_guitar.is_vintage())
from Prac_06.guitar import Guitar guitars = [] name = input("name:") while name != "": year = int(input("Year:")) cost = float(input("Cost:")) guitar = Guitar(name, year, cost) guitars.append(guitar) print("{} ({}) : {} added".format(name, year, cost)) name = input("name:") # guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) print("These are my guitars:") for i, guitar in enumerate(guitars, 1): if guitar.is_vintage(): vintage_string = "(Vintage)" else: vintage_string = "" print("Guitar {}: {:>20} ({}), worth ${:10,.2f} {}".format( i, guitar.name, guitar.year, guitar.cost, vintage_string))