Question: How do you create a function for a given Fahrenheit value that calculates the celsius temperature?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Language: Python

Question: How do you create a function for a given Fahrenheit value that calculates the celsius temperature?

 

(^) Python fo ×
wex Eligible E> X
Logout
I MasterCla X
Bb CS170 Fil X
CS170 File X
Bb Syllabus c X
anaconda X
as Average o X
as Python pr X
My Tutori X
O File | JUsers/arturkrysiuk/Downloads/CS170%20FileFun%20(2).pdf
A
CS170 FileFun
2 / 3
100%
+ | 0 O
Temperature Conversion:
In this problem, you are going to read a series of float values from the file. Assuming that the
values are Fahrenheit temperatures, your program should convert these values one at a time
into respective celsius values and display them on the console screen. For a given Fahrenheit
value, the celsius temperature can be calculated as the following:
celsius = (fahrenheit
32) / 1.8
You should create a function to complete this program as the following:
# complete the following function
def convertTemp(fahrenheit):
try:
# use the given equation to convert the
# Fahrenheit value to celsius value
# return the value
except: # catch exceptions
print("")
# main function
def main():
try:
infile =
open ("tempdata.txt", "r")
# calculate the sum
of the odd numbers only
# loop through all the values from the file
# one at a time
# convert the temperature by calling the
# convertTemp function
# display the converted value by using print function
it should return the converted value
--
except: # catch exceptions
print("")
# call the main function to begin the program
main()
...
II
Transcribed Image Text:(^) Python fo × wex Eligible E> X Logout I MasterCla X Bb CS170 Fil X CS170 File X Bb Syllabus c X anaconda X as Average o X as Python pr X My Tutori X O File | JUsers/arturkrysiuk/Downloads/CS170%20FileFun%20(2).pdf A CS170 FileFun 2 / 3 100% + | 0 O Temperature Conversion: In this problem, you are going to read a series of float values from the file. Assuming that the values are Fahrenheit temperatures, your program should convert these values one at a time into respective celsius values and display them on the console screen. For a given Fahrenheit value, the celsius temperature can be calculated as the following: celsius = (fahrenheit 32) / 1.8 You should create a function to complete this program as the following: # complete the following function def convertTemp(fahrenheit): try: # use the given equation to convert the # Fahrenheit value to celsius value # return the value except: # catch exceptions print("") # main function def main(): try: infile = open ("tempdata.txt", "r") # calculate the sum of the odd numbers only # loop through all the values from the file # one at a time # convert the temperature by calling the # convertTemp function # display the converted value by using print function it should return the converted value -- except: # catch exceptions print("") # call the main function to begin the program main() ... II
(^) Python fo ×
wex Eligible E> X
Logout
I MasterCla X
Bb CS170 Fil X
CS170 File X
Bb Syllabus c X
anaconda X
as Average o X
as Python pr X
My Tutori X
O File | JUsers/arturkrysiuk/Downloads/CS170%20FileFun%20(2).pdf
A
CS170 FileFun
3 / 3
100%
+ | O O
main()
Format your program as the above and complete the body of the functions in order to
calculate and display the celsius temperatures from the Fahrenheit temperatures given in the
file. For this program, you need to create a text file named "tempdata.txt" and place it in the
same folder as the program file.
Input for this program are from a file named tempdata.txt. Each line of the file contains one
float number. For example, in the following file, your program will read the Fahrenheit values
and display the respective celsius values.
Sample Input (tempdata.txt)
Sample Output
79
26.11
8.89
48
99
37.22
68
20.00
22.22
72
74
23.33
3.33
38
...
II
Transcribed Image Text:(^) Python fo × wex Eligible E> X Logout I MasterCla X Bb CS170 Fil X CS170 File X Bb Syllabus c X anaconda X as Average o X as Python pr X My Tutori X O File | JUsers/arturkrysiuk/Downloads/CS170%20FileFun%20(2).pdf A CS170 FileFun 3 / 3 100% + | O O main() Format your program as the above and complete the body of the functions in order to calculate and display the celsius temperatures from the Fahrenheit temperatures given in the file. For this program, you need to create a text file named "tempdata.txt" and place it in the same folder as the program file. Input for this program are from a file named tempdata.txt. Each line of the file contains one float number. For example, in the following file, your program will read the Fahrenheit values and display the respective celsius values. Sample Input (tempdata.txt) Sample Output 79 26.11 8.89 48 99 37.22 68 20.00 22.22 72 74 23.33 3.33 38 ... II
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education