hom1

profilecumali
cumali_sayan_tempConversion2.py

import os import random import math import statistics import sys # TODO - you can search through this file and look for TODO notes... as you comlplete # them, you can replace with DONE to help figure out what is completed # REMEMBER TO REVIEW RUBRIC to show exactly how many points each TODO is worth and make sure # You aren't missing anything. # There is a discussion on Canvas for each assignment - post help and questions there # TODO - Tell me what you found easy (too easy?) - fill in as you go What_I_Found_Easy = ''' Replace this text with your text - should be a couple sentences but can be more Note that this is a variable line assigning a multiple lines of text to a single variable. You must keep the triple single or double quotes at the top and bottom of this block of text ''' # TODO - Tell me what you found hard (too hard?) - fill in as you go What_I_Found_Difficult = ''' Replace this text with your text - should be a couple sentences but can be more Note that this is a variable line assigning a multiple lines of text to a single variable. You must keep the triple single or double quotes at the top and bottom of this block of text ''' # TODO - Tell me what you learned -fill in as you go What_I_Learned = ''' Replace this text with your text * bullet 1 * bullet 2 ''' # DO NOT MODIFY ANY CODE FROM HERE TO "END OF DO NOT MODIFY BLOCK" randomKey = random.randint(0, 1_000_000) random.seed(randomKey) print("===HEADER BEGIN =======================") print(f'OS {os.sys.platform}') print(f'OS {os.sys.version}') print(f'OS {os.sys.executable}') print(f'USER {os.getlogin()}') print(f'KEY {randomKey}') print(random.randint(0,1000), random.randint(0,1000), random.randint(0,1000)) print("---LEARNED") print(What_I_Learned) print("---Difficult") print(What_I_Found_Difficult) print("---Eacy") print(What_I_Found_Easy) print("===HEADER END =======================") #create some data for use later by student - do not moodify temperatureSample = [] for i in range(0,1000): temperatureSample.append(20.0 + random.random() * 80.0) Instructions= ''' Follow the guidance in the comments (lines with leading # signs) Functions and variables may already be defined but may need to be completed. The method 'pass' is a placeholder that lets a program interpret without errors without having actual code that does anything. If you see 'pass' you will need to replace that with your code To facilitate grading and prevent copying of output, programs will run in your console and generate a unique key that will drive your output so it is different each time you run it, and will not be the same as other students (1 in a million chance) For this assignment you will upload your version of this python file as <name>_tempConversion.py and you will copy and paste the terminal output to a text file <name>_tempConversionOutput.txt and upload as well Some sections of code will similarly marked for non-modification - they are designed to run to assist demonstration and grading. ''' # END OF DO NOT MODIFY BLOCK # TODO replace the pass line with your code # It will convert from fahrenheight to celsius # To convert temperatures in degrees Fahrenheit to Celsius, # subtract 32 and multiply by .5556 (or 5/9). def FtoC(fahrenheight): pass # TODO replace pass with your code and return the value as a number indicating degrees celsius # TEST BLOCK 1 - DO NOT REMOVE ============================================= randomTempF = random.randint(0,1000) randomTempC = FtoC(randomTempF) print(f'convert F={randomTempF} to C{randomTempC}') # END TEST BLOCK 1 ======================================================== # TODO complete this function that prints out a 2 column table of # F and C values for each temperature provided between and including starfF and endF # INCLUDE a HEADER ROW # Bonus1 - can you get the degree sign to work? # Bonus2 - can you get the converted value to display rounded to the nearest degree C? def printTemperatureTable(startF = 0, endF = 212): # TODO output a header line for the table # ~ 1 line of code to write header for a two column output of F and C conversion # TODO - replace pass with code that for degreesF in range (startF,endF): pass # replace pass with code to print out a row #TODO call the printTemperatureTable yourself # WRITE SOMETHING ON THE NEXT LINE that will call the printTemperatureTable method # Remember, we define a function with 'def' but to call it, we remove the def # If values are already assigned you can use the defaults or change by providing y # your own values # TODO lets work with the 1000 temperature samples created at the top of the code # HINT there are built in methods min(object), max(object), sum(object) and len(object) # TIP we have already imported a module statistics into the program - it has useful helper # methods see https://docs.python.org/3/library/statistics.html def printMinimumTemperatureInSample(datasampleArray): pass #TODO print the minimum temperature in datasample and return true def printMaximumTemperatureInSample(datasampleArray): pass #TODO print the maximum temperature in datasample and return true def printAverageTemperatureInSample(datasampleArray): pass #TODO print the average temperature in datasample and return true # HINT - you can use the statistics module to make this a one line method def printStandardDeviationInTemperatureInSample(datasampleArray): pass #TODO print the standard deviation temperature in datasample and return true # TEST BLOCK 2 - DO NOT REMOVE ============================================= printMinimumTemperatureInSample(temperatureSample) printMaximumTemperatureInSample(temperatureSample) printAverageTemperatureInSample(temperatureSample) printStandardDeviationInTemperatureInSample(temperatureSample) def printExceptionInformation(): exception_type, exception_object, exception_traceback = sys.exc_info() filename = exception_traceback.tb_frame.f_code.co_filename line_number = exception_traceback.tb_lineno print(f"------EXCEPTION on line {line_number}: {exception_type} in file {filename} ") def TestErrorHandling(temperaturesToTest, nameOfTest): passedMinTest = False passedMaxTest = False passedAverageTest = False passedStdDevTest = False try: passedMinTest = printMinimumTemperatureInSample(temperaturesToTest) passedMaxTest = printMaximumTemperatureInSample(temperaturesToTest) passedAverageTest = printAverageTemperatureInSample(temperaturesToTest) passedStdDevTest = printStandardDeviationInTemperatureInSample(temperaturesToTest) if(passedMinTest and passedMaxTest and passedAverageTest and passedStdDevTest): print(f"Passed Test {nameOfTest}") else: if(not passedMinTest): print("FAIL - printMinimumTemperatureInSample didn't return true") if(not passedMaxTest): print("FAIL - printMaximumTemperatureInSample didn't return true") if(not passedAverageTest): print("FAIL - printAverageTemperatureInSample didn't return true") if(not passedStdDevTest): print("FAIL - printStandardDeviationInTemperatureInSample didn't return true") except: printExceptionInformation() print(f"Failed Test {nameOfTest}") #RUN TESTS emptyList = [] nullList = None setInsteadOfList = {1,2,3,4} tupleInsteadOfList = (5,6,7,8) TestErrorHandling(temperatureSample, "Temperature Sample") TestErrorHandling(emptyList, "EMPTY ") TestErrorHandling(nullList, "nullList") TestErrorHandling(setInsteadOfList, "tupleInsteadOfList") # END TEST BLOCK 2 ======================================================== # Leave the input("Hit Enter to Continue") line, it will give you an opportunity # to copy the console before it goes away. To dismiss the console (program), # hit the "ENTER" key after successfullly copying your console to a text file # input("Hit Enter to Continue")