""" oops.py ============================================================ """ # get inputs reply1 = input( "Enter an integer: " ) reply2 = input( "Enter an integer: " ) # convert inputs into integers n1 = int( reply1 ) n2 = int( reply2 ) # compute their product, quotient, and remainder product = n1 * n2 quotient = n1 // n2 remainder = n1 % n2 # print calculations print( product ) print( quotient ) print( remainder ) """ geom.py ============================================================ """ # get input reply = input( "Enter two integers: " ) # convert input into integers x and n w1, w2 = reply.split() x = int( w1 ) n = int( w2 ) # calculate result - follow the given formula result = 1 + ( 1 - x ** n ) // ( 1 - x ) # print result print( result ) """ rss.py ============================================================ """ # get input reply = input( "Enter text: " ) # get and print version of input with hyphens instead of spaces version1 = reply.replace( " ", "-" ) # replace all spaces in the string reply with hyphens print( version1 ) # get and print version of input without leading or trailing whitespce version2 = reply.strip() print( version2 ) # split input into two words w1, w2 = reply.split() # print first input word in upper case w1 = w1.upper() print( w1 ) # print second input word in lower case w2 = w2.lower() print( w2 ) """ duck.py ============================================================ """ reply = input( "Enter text: " ) # print list of words words = reply.split() print( words ) # print integer list of word lengths word_lengths = [] for word in words: word_length = len( word ) word_lengths.append( word_length ) # print length of the longest word longest_word_length = max( word_lengths ) print( longest_word_length ) # print longest word # the longest word is in the same index position in words as the longest length in the word_lengths list i = word_lengths.index( longest_word_length ) # find the index of the longest_word_length in word_lengths # find() is only for strings longest_word = words[i] print( longest_word ) """ spach.py ============================================================ """ # get access to random value manipulation import random reply1 = input( "Enter seed (integer): " ) reply2 = input( "Enter text: " ) # set seed n = int( reply1 ) # get the int version as the seed NOT THE STRING - the question asked for the int version random.seed( n ) # determine list of words and print them words = reply2.split() print( words ) # print seven words from the word list for i in range( 0, 7 ): word = random.choice( words ) # get a random word from words print( word ) """ manx.py ============================================================ """ # get access to web files import url # testing repository REPOSITORY = "http://www.cs.virginia.edu/~cs1112/datasets/testing/" # get filename filename = input( "Enter file name: " ) # specify link link = REPOSITORY + filename # get dataset dataset = url.get_dataset( link ) # print dataset print( dataset ) # determine maximum value in dataset # max of dataset itself will not work because it finds the "max" list since an element in dataset is a row # we want to find the max value of all cells in all the lists # 1 strategy: # get the max value of each row and make a new list of maxes # the max thing in the first row, the second row, ... maxes = [] for row in dataset: # get the max of the current row row_max = max( row ) # then append this max to our list accumulator maxes maxes.append( row_max ) # when we"ve found all the maxes in all the rows # we get the max value of all the maxes overall_max = max( maxes ) print( overall_max )