# ''' PB.PY ''' # # JIFFIES_PER_SECOND = 100 # reply = input( 'Enter time(jiffies): ') # n = int( reply ) # seconds = n / JIFFIES_PER_SECOND # print( seconds ) # ''' STRAY.PY ''' # reply = input('Enter string: ') # character_list = [] # list accumulator # for ch in reply: # go through each character in text # character_list.append( ch ) # add that character to list # print( character_list ) # ''' FOREIGN.PY ''' # reply = input('Enter number: ') # n = int( reply ) # total = 0 # number accumulator since we're accumulating a sum # for i in range(0, n): # Goes from 0 to n - 1 (our last fraction is n-1/n) # fraction = i/n # Calculate the fraction i/n for the i value we're on # total = total + fraction # Add the fraction to our total # print( total ) # ''' DOUBLE_VISION.PY ''' # reply = input('Enter text: ') # words = reply.split() # Get a list of words # doubling_list = [] # The list we're going to build up # for word in words: # Go through each word in our words list # # Just add the word we're on to the list twice! # doubling_list.append( word ) # doubling_list.append( word ) # print( doubling_list ) # Alternate scarier way: # for word in words: # For each word # for i in range(0,2): # Do the statements indented into this loop twice # doubling_list.append( word ) # Add the word to the list # print( doubling_list ) ''' TRIANGLE.PY ''' # Slicing Way: # reply = input('Enter text: ') # Get a string # n = len( reply ) # Get the length of the string # for i in range(0, n): # Go from 0 to n - 1 # # Just print out a slice of the string from the beginning to the index i # s = reply[ 0:i+1 ] # print( s ) # print out smaller substrings as you go! # Double For Loop way # reply = input('Enter text: ') # Get a string # n = len( reply ) # Get the length of the string # for i in range(0, n): # Go from 0 to n - 1 # for j in range( 0, i+1): # print(reply[j], end='') # print() # Accumulator Way # reply = input('Enter text: ') # Get a string # n = len( reply ) # Get the length of the string # string_accumulator = '' # Initialize a string accumulator # for ch in reply: # Go through each character in reply # string_accumulator = string_accumulator + ch # Add the character to the string accumulator # print( string_accumulator ) # print out current string accumulator ''' ABILITY.PY ''' import url BASE_FOLDER = 'http://www.cs.virginia.edu/~cs1112/words/' file_name = input( 'Enter file name: ' ) word = input('Enter word: ') link = BASE_FOLDER + file_name # Assemble the full link using folder + file # Webpage text is stored as a string in variable text text = url.get_contents( link ) print( 'Text', text ) words = text.split() # Get a list of words from the text file print( 'Words', words ) count_word = words.count( word ) # Count the number of times the word occurs # in your list of words number_words = len( words ) # Length of words list fraction = count_word / number_words # print( count_word ) # print( number_words ) # print( fraction ) # # s = 'peace' # s.upper() # This code does not change the value of s - it's immutable. # print( s ) # # #