Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
  • Use f_strings to output variables.

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.
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
expand button
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
Check Mark
Step 1

Code:


from tabulate import tabulate

import random
randomlist = []
for i in range(0,50):
    n = random.randint(-40,40)
    randomlist.append(n)
print(randomlist)

max(randomlist)

min(randomlist)

print("Lowest temp is {} highest temp is {}".format(max(randomlist),min(randomlist)))

for i in range(0,50):
    if(randomlist[i] == 0):
        index = i

print("0C at index ",index)

sublist=random.sample(randomlist, 10)
sublist.sort()
print(sublist)

def newFunction(sublist):
    sublist2 = []
    for C_val in sublist:
        f_val = (C_val * 1.8) + 32  
        sublist2.append(f_val)
    return sublist2

newList=newFunction(sublist)

print(sublist)

print(newList)

print (tabulate(zip(sublist,newList), headers=["CELSIUS", "FARHENHEIT"]))

print(sum(sublist)/len(sublist) "         "+ sum(newList) / len(newList)"    <-- averages")

 

Knowledge Booster
Background pattern image
Computer Science
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education