Answered You can hire a professional tutor to get the answer.

QUESTION

import string from graphics import * # tells the user what the program does def printGreeting(): print "This program finds hailstone sequences of...

import stringfrom graphics import *# tells the user what the program doesdef printGreeting():print "This program finds hailstone sequences of numbers that you input."print "The output numbers are found based on if it is odd or even."print "If the number is odd, it is multiplied by 3 and then 1 is added to"print "it. If the number is even its divided in half."# gives the user menu optionsdef printMenu():print "ntI : View sequences for an Individual valuen"print "tR : View sequences for a Range of Valuesn"print "tL : find the Longest Chainn"print "tH : view a Histogram of chain lengths for a rangen"print "tQ : Quitnnn"# returns number if it is odddef isOdd(n):return n % 2 == 1# creates a sequence of numbers and prints them outdef hailstone(num):sequence = [num]print "n %d -->>" % num,while num != 1:# odd number is multiplied by 3 and then adds 1# number is added to sequenceif isOdd(num):sequence.append(num)num = (num * 3) + 1# even number is divided by 2# number is added to sequenceelse:sequence.append(num)num = num / 2# prints numbersif num != 1:print num, "-->>",else:# determines length of sequence and prints lengthlength = len(sequence)print "; length = ", lengthreturn length# finds the longest sequence in a range of numbers does not print them out# for the L option on menudef hailstone2(num):length = 1while num != 1:if isOdd(num):num = (num * 3) + 1length = length + 1else:num = num / 2length = length +1return length# error checks for bad numbersdef getValidInt(question, min, max):# use a bad value to enter the loopvalue = max + 1# compose the promptprompt = question + " (" + str(min) + "-" + str(max) + "): "# continue to get values until the user enters a valid onewhile value == "" or value < min or value > max:value = raw_input(prompt)if len(value) != 0:value = int(value)# return a valid valuereturn valuedef longChain():quest1 = "Enter the starting interger "quest2 = "Enter the ending interger "startNum = getValidInt(quest1, 1, 10000)stopNum = getValidInt(quest2, startNum + 1, 10000)largestChain = startNumfor i in range(startNum, stopNum+1):if largestChain <= hailstone2(i):largestChain = ilength = hailstone2(i)print largestChain, " had the longest chain ", lengthdef histogram():# initialize variableslongestLength = 1list = []start = input("Please enter the beginning interger for the range: ")for n in range(start, start + 10):length = hailstone2(n)list.append(length)if longestLength <= hailstone2(n):longestLength = nlength = hailstone2(n)print longestLengthprint listdef main():choice = ''quest1 = "Enter the starting interger "quest2 = "Enter the ending interger "quest3 = "Enter a number"printGreeting()# runs program until they quitwhile choice != "Q" and choice != "q":printMenu()choice = raw_input("Enter your Choice: ")# runs program for numbers in rangeif choice == "r" or choice == "R" :start = getValidInt(quest1, 1, 10000)stop = getValidInt(quest2, start, 10000)for i in range(start, stop +1):hailstone(i)elif choice == "i" or choice == "I":indVal = input("Enter a number (1-10000): ")hailstone(indVal)elif choice == "l" or choice == "L":longChain()elif choice == "h" or choice =="H":histogram()else:print choice, "is not a valid choice"printMenu()choice = input("Please enter your choice : ").upper() BUT I WANT TO use some methods from the graphics library to draw a histogram of chain lengths for a range of values using the drawHistogram() function. This histogram will be drawn in a window thats is 500*500 and entitle it as "Histogram of chainlength".For the y axis,The length of the longest chain plus some room for the labels at the bottom where n is shown.For the x axis, We want to show bars for 10 values and histograms look better if there is some space between the bars AND we'll need some space on the left for the lengths to be printed. Let's try 20.i want to have a range of 10 values and just let the user pick the starting value.want to allow the user to draw histograms for more than one range of numbers during the running of the program, we'll want to close the window after having enough time to view it. You should close the window after 10 seconds. You'll need to use sleep() to do this.All handling of the graphics window should be done within the drawHistogram() function.histogram should look like thishttp://www.cs.umbc.edu/courses/201/fall11/images/histo2.jpgplease i will need much help, i forever appreciate it.thanks in advance

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question