Question

In: Computer Science

Due Sunday, November 1st at 11:59 PM Deliverables There is one deliverable for this assignment hw7.py...

Due

Sunday, November 1st at 11:59 PM

Deliverables

There is one deliverable for this assignment

  • hw7.py

Make sure the script obeys all the rules in the Script Requirements page.

Specification

Your script must print a Kelvin to Fahrenheit conversion table and between a minimum and maximum values, and a Fahrenheit to Kelvin conversion also between a minimum and maximum values.

Here is the formula for converting Kelvin to Fahrenheit

Here is the formula for converting Fahrenheit to Kelvin

The script must have 5 functions

  • get_int
  • kelvin_to_fahrenheit
  • kelvin_to_fahrenheit_table
  • fahrenheit_to_kelvin
  • fahrenheit_to_kelvin_table

get_int

This function must have the following header

def get_int(prompt):

The function prompts the user for a value, converts it to integer and returns the value.

kelvin_to_fahrenheit

This function must have the following header

def kelvin_to_fahrenheit(kelvin):

The function converts a Kelvin temperature to Fahrenheit and returns the Fahrenheit value.

The Fahrenheit value must be an integer.

kelvin_to_fahrenheit_table

This function must have the following header

def kelvin_to_fahrenheit_table(min, max):

The function prints a Kelvin to Fahrenheit conversion table running from min to max.

Before printing the table, the function prints the labels "Kelvin" and "Fahrenheit", followed by a line of dashes.

The Fahrenheit values should align with the "Fahrenheit" label.

See the example below.

fahrenheit_to_kelvin

This function must have the following header

def fahrenheit_to_kelvin(fahrenheit):

The function converts a Fahrenheit temperature to Kelvin and returns the Kelvin value.

The Kelvin value must be an integer.

fahrenheit_to_kelvin_table

This function must have the following header

def fahrenheit_to_kelvin_table(min, max):

The function prints a Fahrenheit to Kelvin conversion table running from min to max.

Before printing the table, the function prints the labels "Fahrenheit" and "Kelvin", followed by a line of dashes.

The Kelvin values should align with the "Kelvin" label.

See the example below.

Script for this assignment

Open an a text editor and create the file hw7.py.

You can use the editor built into IDLE or a program like Sublime.

Test Code

Your hw7.py file must contain the following test code at the bottom of the file

min_kelvin = get_int("Minimum Kelvin temperature: ")
max_kelvin = get_int("Maximum Kelvin temperature: ")
print()
kelvin_to_fahrenheit_table(min_kelvin, max_kelvin)
print()
min_fahrenheit = get_int("Minimum Fahrenheit temperature: ")
max_fahrenheit = get_int("Maximum Fahrenheit temperature: ")
print()
fahrenheit_to_kelvin_table(min_fahrenheit, max_fahrenheit)

You should see something like this

python3 hw7.py
Minimum Kelvin temperature: 255
Maximum Kelvin temperature: 260

Kelvin  Fahrenheit
------------------
255     -1
256     1
257     3
258     5
259     7
260     8

Minimum Fahrenheit temperature: 10
Maximum Fahrenheit temperature: 15

Fahrenheit  Kelvin
-----------------------
10          261
11          261
12          262
13          263
14          263
15          264

The entries in blue are user input.

Suggestions

In other words, write a bit of code, test it, make whatever changes you need to get it working, and go on to the next step.

Write this program in a step-by-step fashion using the technique of incremental development.

  1. Copy only the function headers for the file functions listed above into your script file.
    Under each header, write pass.
    Make sure this statement is indented.
    Run the script.
    Fix any errors you find.
  2. Remove the pass statement from get_int.
    Replace it with a state that use input in an assignment statement to give the variable number a value.
    Convert number into an integer.
    Return number. Run the script.
    Fix any errors you find.
  3. Remove the pass statement from kelvin_to_fahrenheit_table.
    Replace it with a statements that prints the labels and a line of dashes underneath.
    Run the script.
    Fix any errors you find.
  4. Write a for loop gives the loop variable kelvin values from min to max.
    Inside the loop print the value of kelvin,
    Run the script.
    Fix any errors you find.
  5. Remove the pass statement from kelvin_to_fahrenheit. Replace it with an assignment statement that uses a Kelvin to Fahrenheit conversion formula to give the variable fahrenheit a value.
    Return this value.
    Run the script.
    Fix any errors you find.
  6. Repeat the previous 4 steps to complete the script.

Testing on Your Machine

  • Open IDLE
  • Use the Open command in IDLE to open hw7.py
  • Under the Run menu, select Run Module
  • Your output should look something like this
    Minimum Kelvin temperature: 255
    Maximum Kelvin temperature: 260
    
    Kelvin  Fahrenheit
    ------------------
    255     -1
    256     1
    257     3
    258     5
    259     7
    260     8
    
    Minimum Fahrenheit temperature: 10
    Maximum Fahrenheit temperature: 15
    
    Fahrenheit  Kelvin
    -----------------------
    10          261
    11          261
    12          262
    13          263
    14          263
    15          264
    The entries in blue are user input.

Unix Setup

  • Log in to users3.cs.umb.edu
    You will be in your home directory.
  • Go to your it116 directory
    cd it116
  • Go to your hw directory
    cd hw
  • Create a directory for this exercise
    mkdir  hw7
  • Check that the directory was created
    ls

Copy the file to Unix

  • Open FileZilla and connect to users3.cs.umb.edu
    You will have to connect using your Unix username and password.
  • Copy the file to the to it116/hw/hw7

Testing the script on Unix

  • Connect to
    Use an ssh client.
  • Go to the directory for this exercise
    cd  it116/hw/hw7
  • Run this script
    python3  hw7.py
  • Your output should look something like this
    Minimum Kelvin temperature: 255
    Maximum Kelvin temperature: 260
    
    Kelvin  Fahrenheit
    ------------------
    255     -1
    256     1
    257     3
    258     5
    259     7
    260     8
    
    Minimum Fahrenheit temperature: 10
    Maximum Fahrenheit temperature: 15
    
    Fahrenheit  Kelvin
    -----------------------
    10          261
    11          261
    12          262
    13          263
    14          263
    15          264
    The entries in blue are user input.
  • If your script does not run on users3 you will lose points

Solutions

Expert Solution

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote

CODE:

#Function prompts the user for a value, converts it to integer and returns the value.

def get_int(prompt):

    number = input(prompt) #prompts the user for a value

    number = int(number) # converts the number to integer

    return number #returns the number

#Function converts a Kelvin temperature to Fahrenheit and returns the Fahrenheit value.

def kelvin_to_fahrenheit(kelvin):

    fahrenheit = (kelvin - 273.15) * 9/5 + 32 #converts the kelvin temperature to Fahrenheit

    return round(fahrenheit) #return the fahrenheit temperature

#Function prints a Kelvin to Fahrenheit conversion table running from min to max.

def kelvin_to_fahrenheit_table(min, max):

    print("Kelvin Fahrenheit\n------------------")

    for temp in range(min, max+1): #loop through kelvin values from min to max.

        print(temp, end = "\t") #print kelvin temperature

        print(kelvin_to_fahrenheit(temp)) #calling kelvin_to_fahrenheit() and display the Fahrenheit temperature

#Function converts a Fahrenheit temperature to Kelvin and returns the Kelvin value.      

def fahrenheit_to_kelvin(fahrenheit):

    kelvin = (fahrenheit - 32) * 5/9 + 273.15 #converts the Fahrenheit temperature to kelvin

    return round(kelvin) #return the kelvin temperature

#Function prints a Fahrenheit to Kelvin conversion table running from min to max.  

def fahrenheit_to_kelvin_table(min, max):

    print("Fahrenheit Kelvin\n-----------------------")

    for temp in range(min, max+1): #loop through Fahrenheit values from min to max.

        print(temp, end = "\t    ") #print Fahrenheit temperature

        print(fahrenheit_to_kelvin(temp)) #calling fahrenheit_to_kelvin() and display the Kelvin temperature

#program starts here

min_kelvin = get_int("Minimum Kelvin temperature: ")

max_kelvin = get_int("Maximum Kelvin temperature: ")

print()

kelvin_to_fahrenheit_table(min_kelvin, max_kelvin)

print()

min_fahrenheit = get_int("Minimum Fahrenheit temperature: ")

max_fahrenheit = get_int("Maximum Fahrenheit temperature: ")

print()

fahrenheit_to_kelvin_table(min_fahrenheit, max_fahrenheit)

OUTPUT:


Related Solutions

Deliverables There is one deliverable for this assignment hw4.py Make sure the script obeys all the...
Deliverables There is one deliverable for this assignment hw4.py Make sure the script obeys all the rules in the Script Requirements page. Specification The file has entries like the following Barnstable,Barnstable,1 Bourne,Barnstable,5 Brewster,Barnstable,9 ... This script should create a dictionary where the county is the key and then total number of cases for the country is the value. The script should print the name of the county with the highest number of cases along with the total cases. The script...
Deliverables There is one deliverable for this assignment hw6.py Make sure the script obeys all the...
Deliverables There is one deliverable for this assignment hw6.py Make sure the script obeys all the rules in the Script Requirements page. Specification The script must have 3 functions: get_args create_python_file print_directory get_args This function must have the following header: def get_args(arg_number): This function takes as its parameter an integer. The function should look at the number of command line arguments that the script gets when it is run. If the number of command line arguments is less than the...
This assignment is worth 4.0% of your final grade and is due by Thursday, 11:59 PM...
This assignment is worth 4.0% of your final grade and is due by Thursday, 11:59 PM ET of week 7. Instructions There are many tools available to assist you as an RN to organize your thoughts, make nursing judgments, and implement the 5 rights of delegation. SBAR – Situation, Background, Assessment, and Recommendation, is a standardized tool used in many institutions that provides a framework to facilitate clear communication between health care providers. The components of SBAR are as follows,...
PSY 2030 -Assignment 4: One-Way Anova -Due by Sunday, April 19th, at 11:30 PM -Scores out...
PSY 2030 -Assignment 4: One-Way Anova -Due by Sunday, April 19th, at 11:30 PM -Scores out of 25 points (16 points for Question and 9 points for Question 2) -Submit by uploading file(s) within "Assignment 4" on Canvas -SHOW ALL WORK!! Either very clearly type it (making sure your formulas and integrity/formatting of formulas are extremely clear) or write it out by hand and attach a scan or photo of your work. Remember that all assignments must reflect your own...
Econ 335: Assignment 4 Due: April 20th by 11:59 PM 1.     To protect American jobs, the...
Econ 335: Assignment 4 Due: April 20th by 11:59 PM 1.     To protect American jobs, the US government may decide to cut US imports of bulldozers by 60%. It could do so by either: -Imposing a tariff high enough to cut bulldozer imports by 60% -Persuading Komatsu and other foreign bulldozer makers to set up a voluntary export restraint arrangement to cut their exports of bulldozers to the US by 60%. a. Which of these two policies would be less...
PSY 2030-Assignment 3:Chi-Square Tests Due by Sunday, April 12th, at 11:30 PM Scores out of 25...
PSY 2030-Assignment 3:Chi-Square Tests Due by Sunday, April 12th, at 11:30 PM Scores out of 25 points (13 points for Question 1 and 12 points for Question 2) Submit by uploading file(s) within "Assignment 3" on Canvas SHOW YOUR WORK!! Either very clearly type it out (making sure your formulas and integrity/formatting of your formulas are extremely clear) Or write it out by hand and attach a scan or photo of your work Remember that all assignments must reflect your...
CSC 101 Assignment 3 Barista Assistant Due Date: Friday, October 30 at 11:59 PM Learning Objectives:...
CSC 101 Assignment 3 Barista Assistant Due Date: Friday, October 30 at 11:59 PM Learning Objectives: Practice combining your knowledge of conditionals, loops, functions, strings, and lists. What to Submit: Write your program in a Python script named barista.py. Submit this file to the Assignment 3 page on Canvas. Description The purpose of this assignment is to write a Python program for a cafe to help baristas create coffee for a customer. Your program will take the customer's order and...
A Sweaty Weight Lifter Due this Friday, Dec 4 at 11:59 pm (EST) In exercising, a...
A Sweaty Weight Lifter Due this Friday, Dec 4 at 11:59 pm (EST) In exercising, a weight lifter loses 0.142 kg of water through evaporation, the heat required to evaporate the water coming from the weight lifter's body. The work done in lifting weights is 1.38E+5 J. Assuming that the latent heat of vaporization of perspiration is 2.45E+6 J/kg, find the change in the internal energy of the weight lifter.
Ice to Steam via Water Due this Friday, Dec 4 at 11:59 pm (EST) How much...
Ice to Steam via Water Due this Friday, Dec 4 at 11:59 pm (EST) How much heat is required to change a 49.4 g ice cube from ice at -13.7°C to water at 50°C? (if necessary, use cice=2090 J/kg°C and csteam= 2010 J/kg°C) 2.82×104 J You are correct. Your receipt no. is 150-2609 Help: Receipt Previous Tries How much heat is required to change a 49.4 g ice cube from ice at -13.7°C to steam at 120°C?
The actual case study assignment should be uploaded to the Week 6 Assignment Dropbox by 11:59...
The actual case study assignment should be uploaded to the Week 6 Assignment Dropbox by 11:59 p.m. mountain time on Sunday at the end of Week 6. You are encouraged to use the Excel template file provided in Doc Sharing. The Cambridge Company has budgeted sales revenues as follows.                                                                                       Jan                    Feb                  Mar__ Credit sales                                                            $45,000             $36,000             $27,000 Cash sales                                                              27,000             76,500             58,500 Total sales                                                              $72,000          $112,500             $85,500 Past experience indicates that 60% of the credit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT