Python help, i need help on a script thanks for your time! please type a script
ID: 670230 • Letter: P
Question
Python help, i need help on a script thanks for your time! please type a script that I can input and run
If you've ever visited Europe (or Canada) you'll know that they tend to measure temperature in degree Celsius rather than Fahrenheit. Conversion is pretty simple: if f is the temperature in degree Fahrenheit, then the temperature in degree Celsius is
c = (f-32)*5/9.
Write a function convert() that takes as an input degree Fahrenheit and returns degree Celsius.
>>> convert(32)
0.0
>>> convert(68)
20.0
Using your function from part a. write a function table() that prints a formatted look-up table that helps your European and Canadian friends figure out the temperature in Chicago.
>>> table()
F C
-22.0 -30.0
-4.0 -20.0
14.0 -10.0
32.0 0.0
50.0 10.0
68.0 20.0
86.0 30.0
104.0 40.0
This question is about the formatting: make sure the temperatures are displayed with the same precision as shown above and aligned as above.
Explanation / Answer
Part A Code:
#!/usr/bin/python
# Function definition is here
def convert( fahrenheit1 ):
"""This function converts temperature from Fahrenheit to Celsius"""
return (fahrenheit1-32)*5/9;
fahrenheit = 0.0
celsius = 0.0
fahrenheit = input("Please input temperature in degree Fahrenheit")
print
print "Converted temperature in Celsius is: ",convert(fahrenheit)
Part B Code:
#!/usr/bin/python
# Function definition is here
def convert( fahrenheit1 ):
"""This function converts temperature from Fahrenheit to Celsius"""
return (fahrenheit1-32)*5/9;
def table(lookup1):
print " Converison Table"
print " F C"
for lookup in lookup1:
print '{:8.2f} {:8.2f}'.format(lookup,convert(lookup))
return;
lookup1 = [-22.0, -4.0, 14.0, 32.0, 50.0, 68.0, 86.0, 104.0];
fahrenheit = 0.0
celsius = 0.0
#fahrenheit = input("Please input temperature in degree Fahrenheit")
#print "Converted temperature in Celsius is: "+convert(fahrenheit)
table(lookup1)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.