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 main(): """Guitar program, using Guitar class.""" guitars = [] print("My guitars!") guitar_name = input("Name: ") while guitar_name != "": guitar_year = int(input("Year: ")) guitar_cost = float(input("Cost: $")) guitar = Guitar(guitar_name, guitar_year, guitar_cost) guitars.append(guitar) print(str(guitar) + " added.") guitar_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:") i = 1 for guitar in guitars: is_vintage = "" if guitar.is_vintage(): is_vintage = "(vintage)" print("Guitar {}: {} ({}), worth $ {:.2f} {}".format(i, guitar.name, guitar.year, guitar.cost, is_vintage)) i += 1 else: print("No any guitars.")
def main(): guitars = [] print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) add_guitar = Guitar(name, year, cost) guitars.append(add_guitar) print(add_guitar, " 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 index, guitar in enumerate(guitars, 1): is_vintage = "(vintage)" if guitar.is_vintage() else "" print( "Guitar {0}: {1.name:>10} ({1.year}), worth ${1.cost:10,.2f} {2}" .format(index, guitar, is_vintage)) else: print("No guitars :( Quick, go and buy one!")
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 do_chord(options, chord): g = Guitar(frets=options.frets) scope = get_scope(options, g) lines = g.get_chord(chord, scope) for line in lines: print(line)
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: guitars.sort(key=attrgetter("year")) print("These are my guitars:") for i, guitar in enumerate(guitars): vintage_string = "" if guitar.is_vintage(): vintage_string = "(vintage)" print("Guitar {}: {:>20} ({}), worth ${:10,.2f}{}".format(i + 1, guitar.name, guitar.year, guitar.cost, vintage_string)) else: print("No guitars!")
def main(): guitars = [] print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) new_guitar = Guitar(name, year, cost) guitars.append(new_guitar) 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, 1): if guitar.is_vintage(): vintage = "(Vintage)" else: vintage = "" print("Guitar {}: {:<20} ({}), worth ${:10,.2f} {}".format( i, guitar.name, guitar.year, guitar.cost, vintage)) else: print("No guitars?!")
def main(): """Guitar program is worked by Guitar class""" print("My guitars!") name = input("Name: ") while name != "": year = int(input("year: ")) cost = float(input("Cost: $")) add_information = Guitar(name, year, cost) guitars.append(add_information) print(add_information, "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( ) # sorting by year through the __lt__ method in Guitar class print("These are my guitars:") for thing, things in enumerate(guitars): # display number of guitar vintage_string = "" if things.is_vintage(): vintage_string = "(vintage)" print("Guitar {}: {:>20} ({}), worth ${:10,.2f}{}".format( thing, things.name, things.year, things.cost, vintage_string)) else: print("No guitars")
def main(): guitar1 = Guitar("Fender Stratocaster", 2014, 765.40) guitar2 = Guitar("Gibson", 1922, 16000) guitar3 = Guitar("line", 2010, 1965) guitars = [guitar1,guitar2,guitar3] for i,guitar in enumerate(guitars): print("Guitar {}: {}".format(i,guitar))
def do_scale(options, scale): g = Guitar(frets=options.frets) scope = get_scope(options, g) if options.mode == "major": notes = scales.diatonic(scale) elif options.mode == "minor": notes = scales.harmonic_minor(scale) elif options.mode == "natural_minor": notes = scales.natural_minor(scale) elif options.mode == "harmonic_minor": notes = scales.harmonic_minor(scale) elif options.mode == "melodic_minor": notes = scales.melodic_minor(scale) elif options.mode == "ionian": notes = scales.ionian(scale) elif options.mode == "dorian": notes = scales.dorian(scale) elif options.mode == "phrygian": notes = scales.phrygian(scale) elif options.mode == "lydian": notes = scales.lydian(scale) elif options.mode == "mixolydian": notes = scales.mixolydian(scale) elif options.mode == "aeolian": notes = scales.aeolian(scale) elif options.mode == "locrian": notes = scales.locrian(scale) lines = g.get_notes(notes, scope) for line in lines: print(line)
def test_string_tab(net, test_data): net.load_state_dict(torch.load('2fac_checkpoint.pt')) net.eval() criterion = nn.MSELoss() testset = MyDataset(parameters=test_data['parameters'], cqt_spectrograms=test_data['cqt_spec']) testloader = torch.utils.data.DataLoader(testset, batch_size=4, shuffle=False, num_workers=2) inputs, targets = iter(testloader).next() inputs = inputs.to(device) targets = targets.to(device) gt_samples = [] gt_stringNumbers = [] gt_tabs = [] for i in range(len(targets)): gt_stringNumber, gt_tab = targets.cpu().numpy()[i] guitar = Guitar(options=Options()) gt_stringNumbers.append(gt_stringNumber) gt_tabs.append(gt_tab) #print("gt_stringNumber: %.3f, gt_tab: %.3f" % (gt_stringNumber, gt_tab)) audio_buffer = sequencer.play_note(guitar, int(round(gt_stringNumber)), int(round(gt_tab))) #cqt_spec = cqt_transform.compute_cqt_spec(audio_buffer).T #padded_cqt = pad_zeros(cqt_spec, (cqt_spec.shape[1], cqt_spec.shape[1])) gt_samples.append(audio_buffer) with open("2fac_gt_data.pkl", 'wb') as fh: data_dict = {'gt_samples' : np.array(gt_samples), 'gt_stringNumbers' : np.array(gt_stringNumbers), 'gt_tabs' : np.array(gt_tabs), 'gt_cqts' : inputs.cpu().numpy()} pkl.dump(data_dict, fh) fh.close() preds = net(inputs.unsqueeze_(1)) preds = preds.detach().cpu().numpy() pred_samples = [] pred_cqts = [] pred_stringNumbers = [] pred_tabs = [] for i in range(preds.shape[0]): pred_stringNumber, pred_tab = preds[i] guitar = Guitar(options=Options()) #print("pred_stringNumber: %d, pred_tab: %d" % (int(round(pred_stringNumber)), int(round(pred_tab)))) pred_stringNumbers.append(pred_stringNumber) pred_tabs.append(pred_tab) audio_buffer = sequencer.play_note(guitar, int(round(pred_stringNumber)), int(round(pred_tab))) cqt_spec = cqt_transform.compute_cqt_spec(audio_buffer, n_bins=336, bins_per_octave=48, hop_length=256).T padded_cqt = pad_zeros(cqt_spec, (cqt_spec.shape[1], cqt_spec.shape[1])) pred_cqts.append(padded_cqt.T) pred_samples.append(audio_buffer) with open("2fac_pred_data.pkl", 'wb') as fh: data_dict = {'pred_samples' : np.array(pred_samples), 'pred_stringNumbers' : np.array(pred_stringNumbers), 'pred_tabs' : np.array(pred_tabs), 'pred_cqts' : pred_cqts} pkl.dump(data_dict, fh) fh.close() print('test_loss: %.3f' % evaluate(net, testloader))
def main(): gibson = Guitar("Gibson L-5 CES", 1922, 16045.40) another = Guitar("Another Guitar", 2013, 10904.75) print(f"{gibson.name} get_age() - Expected 98. Got {gibson.get_age()}") print(f"{another.name} get_age() - Expected 7. Got {another.get_age()}") print(f"{gibson.name} is_vintage() - Expected True. Got {gibson.is_vintage()}") print(f"{another.name} is_vintage() - Expected False. Got {another.is_vintage()}")
def main(): """Demo a guitar""" guitar_a = Guitar("Gibson L-5 CES", 50, 16035.40) print("{} get age()-Excepted {}.got {}".format(guitar_a.name, guitar_a.get_age(), guitar_a.get_age())) print("{} get is vintage()-Excepted {}.Got {}".format( guitar_a.name, guitar_a.is_vintage(), not (guitar_a.is_vintage())))
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(): """ get information of guitars and print them """ guitars = [] # create the list to store guitar information # get_guitars(guitars) # get user input of guitar information guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # for testing guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) # for testing print_guitars(guitars) # print guitar information
def main(): gibson = Guitar("Gibson L-5 CES", 1922, 16035.40) another_guitar = ( "Another Guitar", 2013, ) print(gibson.get_age()) print(gibson.is_vintage())
def main(): """Test guitar.py module for errors.""" guitar_one = Guitar("Gibson L-5 CE", 1922, 16035.40) # Expected: 99, True guitar_two = Guitar("Martin OM-45", 1930, 265000.00) # Expected: 91, True guitar_three = Guitar("Jazzmaster Squier", 1990, 399.00) # Expected: 31, False print(f"{guitar_one.name} get_age() - Expected 99. Got {guitar_one.get_age()}") print(f"{guitar_two.name} get_age() - Expected 91. Got {guitar_two.get_age()}") print(f"{guitar_three.name} get_age() - Expected 31. Got {guitar_three.get_age()}") print(f"{guitar_one.name} is_vintage() - Expected True. Got {guitar_one.is_vintage()}") print(f"{guitar_two.name} is_vintage() - Expected True. Got {guitar_two.is_vintage()}") print(f"{guitar_three.name} is_vintage() - Expected False. Got {guitar_three.is_vintage()}")
def sample_params_pitch_sf(size): freqs = np.array(utils.compute_freqs(num_frets)) character_variation = np.array([np.random.uniform(0, 1) for _ in range(size)], dtype=np.float32) string_damping = np.array([np.random.uniform(0, 0.7) for _ in range(size)], dtype=np.float32) string_damping_variation = np.array([np.random.uniform(0, 0.5) for _ in range(size)], dtype=np.float32) pluck_damping = np.array([np.random.uniform(0, 0.9) for _ in range(size)], dtype=np.float32) pluck_damping_variation = np.array([np.random.uniform(0, 0.5) for _ in range(size)], dtype=np.float32) string_tension = np.array([np.random.uniform(0, 1) for _ in range(size)], dtype=np.float32) stereo_spread = np.array([np.random.uniform(0, 1) for _ in range(size)], dtype=np.float32) smoothing_factor = np.array([np.random.uniform(0.5, 1) for _ in range(size)], dtype=np.float32) pitch = np.array([np.random.choice(freqs) for _ in range(size)], dtype=np.float32) # ipdb.set_trace() options = [] guitars = [] audio_buffers = [] cqt_specs = [] for i in range(size): options.append(Options(character_variation[i], string_damping[i], string_damping_variation[i], pluck_damping[i], pluck_damping_variation[i], string_tension[i], stereo_spread[i])) guitars.append(Guitar(options=options[i])) audio_buffers.append(sequencer.play_note(guitars[i], 0, 0, pitch[i], smoothing_factor[i])) # print(audio_buffers[i]) # try: # cqt_spec = compute_cqt_spec(audio_buffers[i]).T # except ParameterError: # print(audio_buffers[i]) cqt_spec = compute_cqt_spec(audio_buffers[i]).T padded_cqt = pad_zeros(cqt_spec, (cqt_spec.shape[1], cqt_spec.shape[1])) cqt_specs.append(padded_cqt) cqt_specs = np.array(cqt_specs, dtype=np.float32) print(cqt_specs.shape) return character_variation, string_damping, string_damping_variation, pluck_damping, pluck_damping_variation, string_tension, stereo_spread, pitch, smoothing_factor, cqt_specs
def main(): print("My guitars!") name = input("Name: ") while name != "": while True: try: year = int(input("Year: ")) break except ValueError: print("Invalid year, please try again.") while True: try: cost = float(input("Cost: $")) break except ValueError: print("Invalid cost, please try again.") guitars.append(Guitar(name, year, cost)) print(f"{name} ({year}) : ${cost:.2f} added.") name = input("\nName: ") # guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) # guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) print("\nThese are my guitars:") for i, guitar in enumerate(guitars, 1): is_vintage = " (vintage)" if guitar.is_vintage() else "" print( f"Guitar {i}: {guitar.name} ({guitar.year}), worth $ {guitar.cost:,.2f}{is_vintage}" )
def get_new_guitar(): """Get new guitar details from a user.""" name = input("Enter the guitars name: ") year = int(input("What year was it made? ")) cost = float(input("How much does it cost? ")) return Guitar(name, year, cost)
def save_data_hdf5(fname, size): print('Generating {}...'.format(fname)) freqs = np.array(utils.compute_freqs(num_frets)) character_variation = np.array([np.random.uniform(0, 1) for _ in range(size)], dtype=np.float32) string_damping = np.array([np.random.uniform(0, 0.7) for _ in range(size)], dtype=np.float32) string_damping_variation = np.array([np.random.uniform(0, 0.5) for _ in range(size)], dtype=np.float32) pluck_damping = np.array([np.random.uniform(0, 0.9) for _ in range(size)], dtype=np.float32) pluck_damping_variation = np.array([np.random.uniform(0, 0.5) for _ in range(size)], dtype=np.float32) string_tension = np.array([np.random.uniform(0, 1) for _ in range(size)], dtype=np.float32) stereo_spread = np.array([np.random.uniform(0, 1) for _ in range(size)], dtype=np.float32) smoothing_factor = np.array([np.random.uniform(0.5, 1) for _ in range(size)], dtype=np.float32) pitch = np.array([np.random.choice(freqs) for _ in range(size)], dtype=np.float32) with h5py.File(fname, 'w') as f: dset_parameters = f.create_dataset('parameters', (size, 9), maxshape=(None, None), dtype='float32', chunks=(size, 9)) dset_cqt_specs = f.create_dataset('cqt_spec', (size, 336, 336), maxshape=(None, None, None), dtype='float32', chunks=(1000, 336, 336)) dset_parameters[:] = np.array([character_variation, string_damping, string_damping_variation, pluck_damping, pluck_damping_variation, string_tension, stereo_spread, pitch, smoothing_factor]).T for i in range(size): options = Options(character_variation[i], string_damping[i], string_damping_variation[i], pluck_damping[i], pluck_damping_variation[i], string_tension[i], stereo_spread[i]) guitar = Guitar(options=options) audio_buffer = sequencer.play_note(guitar, 0, 0, pitch[i], smoothing_factor[i]) cqt_spec = compute_cqt_spec(audio_buffer).T padded_cqt = pad_zeros(cqt_spec, (cqt_spec.shape[1], cqt_spec.shape[1])) dset_cqt_specs[i, :, :] = padded_cqt print('Finished generating {}!'.format(fname))
def main(): done = False guitars = [] print("My guitars!") while not done: name = input("Name: ") if not name: break else: try: year = int(input("Year: ")) if not year: raise Exception except: year = 0 try: cost = float(input("Cost: $")) if not cost: raise Exception except: cost = 0 guitars.append(Guitar(name, year, cost)) print("These are my guitars:") for i, guitar in enumerate(guitars, 1): print( f"Guitar {i:>{math.ceil(math.log(len(guitars),10))}}: {str(guitar): <{len(max(str(guitar) for guitar in guitars))}s}", '(vintage)' if guitar.is_vintage() else '')
def __init__(self, **kwargs): self.frets = kwargs.pop('frets') self.strings = kwargs.pop('strings') self.lefty = kwargs.pop('lefty') super(GuitarScreen, self).__init__(**kwargs) global noteButtons print(self.lefty) print(ORIENTATIONTABLE[0]) if self.lefty == ORIENTATIONTABLE[0]: order = -1 else: order = 1 self.guitar = Guitar(number_of_frets=self.frets, tuning=self.strings, is_lefty=self.lefty) self.cols = self.frets self.rows = len(self.strings) + 2 for string in self.guitar.strings: for note in string.notes[::order]: a = Button(text=str(note[0])) a.bind(on_press=self.callback) noteButtons.append(a) self.add_widget(a) for i in range(self.frets)[::order]: self.add_widget(Label(text=str(i))) for fret_marker in self.guitar.fret_markers: self.add_widget(Label(text=str(fret_marker)))
def main(): print("My guitars!") guitars = [] guitars.append(Guitar("Fender Stratocaster", 2014, 765.40)) guitars.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) for i, guitar in enumerate(guitars): print("Name:", guitar.name) print("Year:", guitar.year) print("Cost:", guitar.cost) print("{} ({}) : {} added.".format(guitar.name, guitar.year, guitar.cost)) print("These are my guitars:") for i, guitar in enumerate(guitars): print("Guitar {}: {} ({}), worth ${:10,.2f} ({})".format( i + 1, guitar.name, guitar.year, guitar.cost, guitar.is_vintage()))
def main(): """Test Guitar Class functionality.""" first_guitar = Guitar("Gibson L-5 CES", 1922, 16035.40) second_guitar = Guitar("Another Guitar", 2013, 1500.12) print("{} get_age() - Expected {}. Got {}".format(first_guitar.name, 99, first_guitar.get_age())) print("{} get_age() - Expected {}. Got {}".format(second_guitar.name, 8, second_guitar.get_age())) print("{} is_vintage() - Expected {}. Got {}".format(first_guitar.name, True, first_guitar.is_vintage())) print("{} is_vintage() - Expected {}. Got {}".format(second_guitar.name, False, second_guitar.is_vintage()))
def test(): guitar1 = Guitar('Gibson L-5 CES', 1922, 16035.40) guitar2 = Guitar('Another Guitar', 2013, 10000.00) print('{} get_age() - Expected {}. Got {}'.format(guitar1.name, 98, guitar1.get_age())) print('{} get_age() - Expected {}. Got {}'.format(guitar2.name, 7, guitar1.get_age())) print('{} is_vintage() - Expected {}. Got {}'.format( guitar1.name, True, guitar1.is_vintage())) print('{} is_vintage() - Expected {}. Got {}'.format( guitar2.name, False, guitar2.is_vintage()))
def main(): print("My Guitars!") guitar_list = [] name = input("Name: ") while name != "": year = int(input("Year: ")) cost = float(input("Cost: $")) guitar = Guitar(name, year, cost) guitar_list.append(Guitar(name, year, cost)) print(guitar, "added.") name = input("Name: ") for i, guitar in enumerate(guitar_list): if guitar.is_vintage(): vintage_string = "(vintage)" else: vintage_string = "" print("Guitar {}: {:>20} ({}), worth ${:10,.2f} {}".\ format(i+1, guitar.name, guitar.year, guitar.cost, vintage_string))
def main(): 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, 97, guitar.get_age())) print("{} get_age() - Expected {}. Got {}".format(other.name, 7, other.get_age())) 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(): """Store all of input guitars in a list, then print their details.""" guitars = [] print("My guitars!") guitar_name = get_valid_string("Name: ") while guitar_name != "": guitar_year = get_valid_integer("Year: ") guitar_cost = get_valid_float("Cost: $") guitars.append(Guitar(guitar_name, guitar_year, guitar_cost)) print(f"{guitar_name} ({guitar_year}) : ${guitar_cost:.2f} added.\n") guitar_name = get_valid_string("Name: ") print("These are my guitars:") display_all_guitars(guitars)
def read_guitars(): """Open the file guitars.csv and return the contents.""" guitars = [] in_file = open('myguitars.csv', 'r') for line in in_file: parts = line.strip().split(',') year = int(parts[1]) cost = float(parts[2]) guitar_to_add = Guitar(parts[0], year, cost) guitars.append(guitar_to_add) return guitars
def get_guitars(guitars): """ get guitar information including name, year and cost from user input """ print("My guitars!") name = input("Name: ") while name != "": year = int(input("Year: ")) cost = int(input("Cost: ")) guitar = Guitar(name, year, cost) guitars.append(guitar) print("---------------------------------") name = input("Name: ")
def main(): guitars_list = [] print("My guitars!") name = input("Name:") while True: if name != "": year = input("Year:") cost = input("Cost:") add_guitars = Guitar(name, year, cost) guitars_list.append(add_guitars) print(name, year, cost, "added") name = input("Name:") else: for i in guitars_list: print(i) break guitars_list.append(Guitar("Gibson L-5 CES", 1922, 16035.40)) guitars_list.append(Guitar("Line 6 JTV-59", 2010, 1512.9))
def run_tests(): """Tests for Guitar class.""" guitar1 = Guitar("Guitar1", 1950, 9999.9) guitar2 = Guitar("Guitar2", 2002, 4999.9) print("{} get_age() - Expected {}. Got {}".format(guitar1.name, 67, guitar1.get_age())) print("{} get_age() - Expected {}. Got {}".format(guitar2.name, 15, guitar2.get_age())) print() print("{} is_vintage() - Expected {}. Got {}".format( guitar1.name, True, guitar1.is_vintage())) print("{} is_vintage() - Expected {}. Got {}".format( guitar2.name, False, guitar2.is_vintage()))
def main(): guitar1 = Guitar("Fender Stratocaster",1923,765.4) print ('guitar1.get_age() - Expected 93. Got {}'.format(guitar1.get_age())) print ('guitar1.is_vintage - Expected True. Got {}'.format(guitar1.is_vintage())) print('') guitar2 = Guitar("Fender Stratocaster",1967,765.4) print ('guitar2.get_age() - Expected 49. Got {}'.format(guitar2.get_age())) print ('guitar2.is_vintage - Expected False. Got {}'.format(guitar2.is_vintage()))
from guitar import Guitar Gibson = Guitar("Gibson L-5 CES" , 1922, 16035.40) Hendjai = Guitar("Hendjai L-4 DUN", 2010, 16035.40) print(Gibson) print(Gibson.get_age()) print(Gibson.is_vintage()) print(Hendjai) print(Hendjai.get_age()) print(Hendjai.is_vintage())
from guitar import Guitar test = Guitar("test", 1992, 100) print(test) test.get_age() print(test.is_vintage()) guitars = [] guitars.append(Guitar("Gibson L-5 CES", 1992, 16035.40)) guitars.append(Guitar("Line 6 JTV-59", 2010, 1512.9)) for i, guitar in enumerate(guitars): print("Guitar {}: {:>20} ({}), worth ${:10,.2f}".format(i + 1, guitar.name, guitar.year, guitar.cost))
from guitar import Guitar guitar1 = Guitar("Fender Stratocaster", 2014, 765.40) guitar2 = Guitar("Gibson L-5 CES", 1922, 16032.40) print(guitar1.get_age()) print(guitar2.get_age()) print(guitar1.is_vintage()) print(guitar2.is_vintage())
from guitar import Guitar my_guitar = Guitar("Fender Stratocaster", 1954, 25000) print(my_guitar) print(my_guitar.get_age()) print("This guitar is vintage: {}".format(my_guitar.is_vintage()))
def main(): g1 = Guitar("abc", 1910, 65) g1.get_age() if g1.is_vintage(): print("vintage") print(g1)
from guitar import Guitar gibson = Guitar("Gibson L-5 CES", 1922, 16035.40) new = Guitar("GG", 2010, 19000) print(gibson) print(gibson.get_age()) print(gibson.is_vintage()) print(new.get_age()) print(new.is_vintage())