This program requires the main function and a custom value-returning function. In the main function, code these steps in this sequence: use a list comprehension to generate 50 random integers all from -40 to 40, inclusive. These represent Celsius temperatures. use an f_string to report the lowest and highest Celsius temperature in the list. determine if 0C is in the list. If it is report the index where it first occurs. If it isn't in the list, report that, too. use a random module method to create a sublist of 10 unique Celsius temperatures. sort this sublist in ascending order. pass the Celsius sublist as the sole argument to the custom value-returning function. In the custom function: use either a loop or a list comprehension to create a list of 10 Fahrenheit temperatures equivalent to the Celsius temperatures. A bonus of 3 points will be awarded if a list comprehension is employed. return the Fahrenheit list to main. Back in main: use a for loop and the range function to print a table showing the equivalent Celsius and Fahrenheit temperatures in columns with widths that you choose. include column headings and display the averages as shown below.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This program requires the main function and a custom value-returning function.
In the main function, code these steps in this sequence:

  • use a list comprehension to generate 50 random integers all from -40 to 40, inclusive. These represent Celsius temperatures.
  • use an f_string to report the lowest and highest Celsius temperature in the list.
  • determine if 0C is in the list. If it is report the index where it first occurs. If it isn't in the list, report that, too.
  • use a random module method to create a sublist of 10 unique Celsius temperatures.
  • sort this sublist in ascending order.
  • pass the Celsius sublist as the sole argument to the custom value-returning function.

In the custom function:

  • use either a loop or a list comprehension to create a list of 10 Fahrenheit temperatures equivalent to the Celsius temperatures. A bonus of 3 points will be awarded if a list comprehension is employed.
  • return the Fahrenheit list to main.

Back in main:

  • use a for loop and the range function to print a table showing the equivalent Celsius and Fahrenheit temperatures in columns with widths that you choose.
  • include column headings and display the averages as shown below.

Sample Output

 

Lowest temp is -39C and highest is 40c
Found OC at index 3
Sorted sample of ten equivalent temperatures
CELSIUS
FAHRENHEIT
-24
-11.2
-21
-5.8
-17
1.4
-9
15.8
-6
21.2
-1
30.2
17
62.6
18
64.4
24
75.2
24
75.2
0.5
32.9
<--- averages
Transcribed Image Text:Lowest temp is -39C and highest is 40c Found OC at index 3 Sorted sample of ten equivalent temperatures CELSIUS FAHRENHEIT -24 -11.2 -21 -5.8 -17 1.4 -9 15.8 -6 21.2 -1 30.2 17 62.6 18 64.4 24 75.2 24 75.2 0.5 32.9 <--- averages
Expert Solution
Python Program

import random

def CelsiusToFahrenheit(lstCel):
    lstFah = []
    
    for i in lstCel:
        x = (i * 1.8) + 32
        lstFah.append(x)
        
    return lstFah

def main():
    lst = [random.randint(-40,40) for i in range(50)]
    
    x = min(lst)
    y = max(lst)
    print(f"Lowest temp is {x}C and highest is {y}C")
    
    
    if 0 in lst:
        ind = lst.index(0)
        print("Found 0C at index", ind)
    else:
        print("0C is not in the list")
    
    lstCel = []
    x = random.randint(-40, 40)
    for i in range(10):
        while x in lstCel:
            x = random.randint(-40, 40)
        lstCel.append(x)
          
    lstCel.sort()
    print("Sorted list of ten equivalent temperatures")
    
    lstFah = CelsiusToFahrenheit(lstCel)
    print("CELSIUS\t\tFahrenheit")
    sum1 = 0
    sum2 = 0
    for i in range(10):
        sum1 = sum1 + lstCel[i]
        sum2 = sum2 + lstCel[i]
        x = "{:.2f}".format(lstFah[i])
        print(lstCel[i], "\t\t", x)
    
    print((sum1/10), "\t\t", (sum2/10), "\t\t<---  averages")

if __name__=="__main__":
    main()

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY