def main(): guitars = [] print("My guitars!") name = input("Name: ") if name != "": year = int(input("Year: ")) cost = float(input("Cost: ")) guitars_to_add = Guitar(name, year, cost) guitars.append(guitars_to_add) print(guitars_to_add, "added") guitar.append(Guitar("Gibson L-5 CES", 1922, 16035.50)) guitar.append(Guitar("Line 6 JTV-59", 2010, 1512.90)) guitars.sort() print("These are my guitars: ") if guitars is not None: for i, guitar in enumerate(guitars): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" """This is the answer. Look at the code in depth - 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(): guitars = [] guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) add_guitar(guitars) print("These are my guitars: ") for i, guitar in enumerate(guitars): if guitar.is_vintage(): vintage_string = "(vintage)" else: vintage_string = "" print("Guitar {}: {:>20} ({}), worth ${:10,.2f} {}".format( i + 1, guitar.name, guitar.year, guitar.price, vintage_string))
def main(): stratcat = Guitar("Fender Stratocaster", 1954, 37500) fatcat = Guitar("Gibson Hamburger", 1980, 20) print(stratcat) print(stratcat.get_age()) print(stratcat.is_vintage()) print(fatcat) print(fatcat.get_age()) print(fatcat.is_vintage())
def main(): """Tests for Guitar class.""" 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(): Guitar_list = [] print("My Guitars!") name = str(input("Name:")) while name != "": year = int(input("Year:")) cost = float(input("Price:")) new_guitar = Guitar(name, year, cost) print("{} ({}) : ${} added".format(name, year, cost)) Guitar_list.append(new_guitar) name = str(input("Name:")) else: for i, guitar in enumerate(Guitar_list): is_vintage_text = "" if guitar.is_vintage(): is_vintage_text = "(vintage)" print("Guitar {0}: {1:>30} ({2}), worth ${3:10,.2f}{4}".format( i + 1, guitar.name, guitar.year, guitar.cost, is_vintage_text))
from guitars import Guitar guitar = Guitar("Gibson L-5 CES", 1922, 16035.4) print(guitar) print("My Guitars!") guitars = [] guitar_name = input("Name: ") while guitar_name != "": guitar_year = int(input("Year: ")) guitar_price = float(input("Price: ")) guitar = Guitar(guitar_name, guitar_year, guitar_price) print("{} added".format(guitar)) guitars.append(guitar) else: guitar_name = input("Name: ") for i, guitar in enumerate(guitars): if guitar.is_vintage(): is_vintage = "(vintage)" else:
def add_guitar(guitars): name = get_guitar_name() year = get_guitar_year() price = get_guitar_price() guitars.append(Guitar(name, year, price)) print("{} ({}) : ${} added".format(name, year, price))