''' Purpose: reconsider Test 1 programming problems. ''' ### phrase.py ---------------------------------- # Output the phrase 'I am honorable' print( 'I am honorable.' ) ### mtom.py ---------------------------------- # Get an input, convert it to an integer, and perform the calculation MINUTES_PER_MOMENT = 1.5 reply = input( "Enter number of moments: " ) moments = int( reply ) time_in_minutes = MINUTES_PER_MOMENT * moments # could've done 1.5 * moments print( time_in_minutes ) ### fila.py ---------------------------------- reply = input( "Enter two strings: " ) # 'Apple Banana' words = reply.split() # ['Apple','Banana'] first_word = min( words ) # 'Apple' last_word = max( words ) # 'Banana' print( first_word ) print( last_word ) # Could've also done: # words = reply.split() # ['Apple','Banana'] # sorted_words = sorted(words) # ['Apple', 'Banana'] (already sorted - sorts them if not) # w1, w2 = sorted_words # w1 gets first word w2 gets second word # print(w1) # print(w2) ### ranly.py --------------------------------- reply = input( 'Enter two integers:' ) m, n = reply.split() m, n = int( m ), int( n ) # Cannot do int( list of strings of numbers ) # Accumulators list_numbers = [] for i in range( m, n+1 ): list_numbers.append( i ) sum_numbers = sum( list_numbers ) # Call sum function on the list of numbers print( list_numbers ) print( sum_numbers ) # Alternate # Accumulators sum_acc = 0 list_numbers = [] for i in range( m, n+1 ): sum_acc = sum_acc + i list_numbers.append( i ) print( list_numbers ) print( sum_acc ) ### lest.py ---------------------------------- # print length of longest word # Accumulator General Format for Lists # list_acc = [] # for ... in ...: # list_acc.append( ... ) reply = input( "Enter text: " ) # 'It was great to see' words = reply.split() # ['It', 'was, 'great','to','see'] list_word_lengths = [] # Accumulator for word in words: length_word = len( word ) list_word_lengths.append( length_word ) # list_word_lengths [2,3,5,2,3] longest_length = max( list_word_lengths ) # 5 is the max in the list print( longest_length ) # print out that variable with the longest word ### tell.py ---------------------------------- # get support to read datasets import url # define the URL for the dataset web folder WEB_FOLDER = "http://www.cs.virginia.edu/~cs1112/datasets/csv/" # get the dataset reply = input( "Enter name of dataset: " ) name = reply.strip() link = WEB_FOLDER + name dataset = url.get_dataset( link ) # List of Lists ex. [[1,2,3], [4,5,6], [7,8,9]] # 0 1 2 3 rows -> indexes 0 1 2 -> 2 is last row index (number rows - 1) # row1 row2 row3 # 3 columns -> indexes 0 1 2 so 2 is last row index (number cols - 1) # analyze the dataset number_rows = len( dataset ) first_row = dataset[0] # Gets us row 1 (first inner list in outer dataset) number_columns_per_row = len( first_row ) number_cells = number_rows * number_columns_per_row first_cell_first_row = first_row[0] # first value in first list (ex. 1) ^ up above last_row = dataset[number_rows - 1] # dataset[ len(dataset) - 1 ] last_cell_last_row = last_row[number_columns_per_row - 1] # last_row[ len(last_row) - 1 ]