?(Python 3.4) Write a function called convertTempString that takes a single non-
ID: 3693637 • Letter: #
Question
?(Python 3.4) Write a function called convertTempString that takes a single non-negative Fahrenheit temperature (as defined for isTempF above) string argument and returns a string that that is the Celsius temperature equivalent. The string must have exactly one place after the decimal followed by the capital C character. You do not have to worry about strings that for which isTempF would say false.. (Hint: You should call your FtoC function to do the arithmetic for the conversion.) Below is a screenshot of how it might be called:
Explanation / Answer
#function convertTempString that takes a string
#as argument and extracts the integer value from
#string and converts the fahrenheit temeprature
#and round to two decimal values and concateneate
#resultant string with 'C'
def convertTempString(temp):
#extract temp string integer value
fahr=int(temp[0:len(temp)-1])
#convert fahr to celsius
celsius= (fahr-32)*(5.0/9.0)
#return resultant converted string
return str(round(celsius,2))+'C'
--------------------------------------------------------------------------------------------------------------------
#Test python program that tests the funciton
#convertTempString with input string of fahrenheit
#temeprature
#f2c.py
#import math package
import math
def main():
#call the function convertTempString
celsius=convertTempString('33F')
#print celsius
print celsius
#function convertTempString that takes a string
#as argument and extracts the integer value from
#string and converts the fahrenheit temeprature
#and round to single decimal values and concateneate
#resultant string with 'C'
def convertTempString(temp):
#extract temp string integer value
fahr=int(temp[0:len(temp)-1])
#convert fahr to celsius
celsius= (fahr-32)*(5.0/9.0)
#return resultant converted string
return str(round(celsius,1))+'C'
#calling main method
main()
----------------------------------------------------------------------------------------------------------------------------
Sample output:
0.6C
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.