Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Write a python
In the main() function:
- Create an empty list named nums.
- Use a for loop to add 15 random integers, inclusive of 41-83, to the list nums, . It is required to use random.randint for generation of the numbers.
- Use a for loop to print the values on the same line, no brackets are expected.
- Use a for loop to sum the list, then print the sum value.
- Sort the list.
- print the sorted values all on the same line using the unpack feature of lists/tuples, no brackets are expected. (Hint use the asterisk in front of the list Example #2)
- make a new list named start by slicing out the first 8 elements of the sorted nums list.
- print the start list in a single print without using unpack feature of lists/tuples, brackets are expected.
- make a new list named finish by slicing out the last 4 elements of the sorted nums list.
- print the finish list in a single print without using unpack feature of lists/tuples, brackets are expected.
- execute the even_odd() function (defined next) with sorted nums as its sole argument.
- print the returned sum values from even_odd() function
- print the final program course message
Inside the even_odd() function:
- Use a for loop to test for and add up the odd or even values from the list nums. When finished, then print the total of each even and odd elements found.
- print the 6th element in the list.
- return even and odd sums
Output:
54 82 75 72 56 64 57 80 74 79 62 81 71 42 69
Sum of the Random numbers list is 1018
42 54 56 57 62 64 69 71 72 74 75 79 80 81 82
[42,42, 56, 62, 64, 69,71]
[79,80,81,82]
List had 9 evens and 6 odds
The 6th element in sorted nums is 64
The sum of Even’s is 586 The sum of odd’s is 432
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images
Knowledge Booster
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
- *Can you produce a flowchart for this code. import randomdef main(): # main function definitionaGrades=[] # empty list to store Gradesfor i in range(7): # loop to read 7 inputsprint("Input scores ",i+1," : ", end="") # a message to enter graden=int(input()) # input gradeaGrades.append(n) # add grade into listprint("Grade list before randomize: ",aGrades) # print list random.shuffle(aGrades) # randomize listnumExams=len(aGrades)-1 # compute numExamsFinalExam=aGrades[-1] # store final gradeTotalPoints=sum(aGrades)-aGrades[-1] # compute TotalPointsTestAverage=TotalPoints/numExams # compute TestAverageFinalAverage=TestAverage*.6 + FinalExam*.4 # compute FinalAverageprint("Grade list after randomize is: ",aGrades) # print listprint("Test Average = %.2f"%TestAverage) # print test averageprint("Final Average = %.2f "%FinalAverage) # print final averagemain() # calling main functionarrow_forwardWhen using a for-loop to modify a list, you always have to make a copy of the list. (a) True (b) False Thank you!arrow_forwardPython please: Given the input file input1.csv write a program that first reads in the name of the input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words in a sorted list. The contents of the input1.csv are: hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy Example: If the input is input1.csv the output is: ['Cat', 'Hello', 'boy', 'boy', 'cat', 'cat', 'dog', 'dog', 'hello', 'hey', 'hey', 'man', 'man', 'woman'] Note: There is a newline at the end of the output.arrow_forward
- Develop a Python program. 1. Create an list to hold 5 elements. 2. Use for loop to collect 5 numbers from user input, save each number to the list 3. calculate the average number of these 5 numbers.arrow_forward_Python_ Create a function positive_sum(my_list) that would calculate the sum of positive values in the list. 1.1. Create a variable that will store your sum and initialize it with zero. 1.2. Go through your list with a loop Check if the current value is positive Add positive value to resulting value 1.3. Return the calculated result Hints: we add the value to the result if the value is positive and otherwise we do nothing. use if inside the loop the loop should be going over all values in the listarrow_forwardIn Python IDLE: how would I write a for loop to reverse the strings within a list? Original list below: [”hi”, “my”, “name”, “is”, “tom”] Output that I want below: [ “ih”, “ym”, “eman”, “si”, “mot” ]arrow_forward
- Python programming only NEED HELP PLEASEarrow_forwardpython LAB: Subtracting list elements from max When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that adjusts a list of values by subtracting each value from the maximum value in the list. The input begins with an integer indicating the number of integers that follow.arrow_forwardIN PYTHON! finish the incomplete program by writing the code that can be placed below the #write the code. use loops to calculate the sums and avg of each row of scores in the list. the following output should be displayed. dont change any part of the code. OUTPUT: Average scores for students: Student # 1: 12.0 Student # 2: 22.0 CODE: students =[ [11, 12, 13], [21, 22, 23] ] avgs = [] # Write your code here: print('Average scores for students: ") for i, avg in enumerate (avgs): print("Student #', i + 1, ':', avg)arrow_forward
- in python pleasearrow_forwardCreate a Python program using the following: -Create list[ "Parking:ID123", "Speeding:"ID455", "Running:ID346"] -Slice the list by ":" -Create a search such that when the user inputs a name, if the name is on the list, print the name and the corresponding ID number or return that there is no match found. -Use control statements (break/continue)arrow_forwardPythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education