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("No guitars :( Quick, go and buy one!")
def run_unit_tests(): guitar = Guitar("Gibson L-5 CES", 1922, 16035.48) another_guitar = Guitar("another Guitar", 2010, 1099.99) print("{} get_age() - Expected 98. Got {}".format(guitar.name, guitar.get_age())) print("{} get_age() - Expected 10. Got {}".format(another_guitar.name, another_guitar.get_age())) print("{} is_vintage() - Expected True. Got {}".format(guitar.name, guitar.is_vintage())) print("{} is_vintage() - Expected False. Got {}".format(another_guitar.name, another_guitar.is_vintage()))
def main(): """Demo code to test out Guitar class""" guitar1 = Guitar("Gibson L-5 CES", 1922, 16035.40) print(guitar1) print(guitar1.get_age()) print(guitar1.is_vintage()) guitar2 = Guitar("Gibson L-5 CES", 2013, 16035.40) print(guitar2) print(guitar2.get_age()) print(guitar2.is_vintage())
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, 5, 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(): name = "Gibson L-5 CES" year = 1922 cost = 16035.40 guitar = Guitar(name, year, cost) another_guitar = Guitar("Another Guitar", 2013, 2000) print("{} get_age() - Expected 98. Got {}".format(guitar.name, guitar.get_age())) print("{} get_age() - Expected 7. Got {}".format(another_guitar.name, another_guitar.get_age())) print("{} is_vintage() - Expected True. Got {}".format( guitar.name, guitar.is_vintage())) print("{} is_vintage() - Expected False. Got {}".format( another_guitar.name, another_guitar.is_vintage()))
def main(): guitars = [] name = input("Name: ") while name != "": year = input("Year: ") cost = input("Cost: $") add_guitars = Guitar(name, year, cost) guitars.append(Guitar(name, year, cost)) print(add_guitars, "added") 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): if guitar.is_vintage(): vintage_string = "(Vintage)" print("Guitar {}: {:>20} ({}), worth ${:10}{}".format( i + 1, guitar.name, guitar.year, guitar.cost, vintage_string)) else: print("Guitar {}: {:>20} ({}), worth ${:10}".format( i + 1, guitar.name, guitar.year, guitar.cost))
def main(): guitars = [] print("My guitars!") # ask for user input name = input("Name: ") while name != " ": year = int(input("Year: ")) cost = float(input("Cost: $")) print("{} ({}) : ${} added.".format(name, year, cost)) guitars.append(Guitar(name, year, cost)) # add to list name = input("Name: ") print("There are my guitars:") # for loop to print each elements in list for i, guitar in enumerate(guitars): if guitar.is_vintage(): # called the method from guitar class vintage_string = "(vintage)" print("Guitar {}: {} ({}), worth ${:3,.2f} {}".format(i + 1, guitar.name, guitar.year, guitar.cost, vintage_string)) else: print("Guitar {}: {} ({}), worth ${:3,.2f}".format(i + 1, guitar.name, guitar.year, guitar.cost))