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 program follows.
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 1 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
- Write the python function selection_sort_descend_trace() that takes an integer list and sorts the list into descending order. The function should use nested loops and output the list after each iteration of the outer loop, thus outputting the list N-1 times (where N is the size). Complete __main__ to read in a list of integers, and then call selection_sort_descend_trace() to sort the list. Ex: If the input is: 20 10 30 40 then the output is: 40 10 30 20 40 30 10 20 40 30 20 10 I have a whitespace error. I need to have a space after the last index position prints but I can't seem to get the space in without either adding a new line. what can i do to fix this?arrow_forwardPlease do fastarrow_forward1 - Write a Python function that will do the following: 1. Ask the user to input an integer that will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers). a. Determine whether each element is an even number or an odd number b. Return a list of five string elements "odd" and "even" that map the indexes of the elements of the input list, according to whether these elements are even or odd numbers.For example: if the input sequence is 12, 13, 21, 51, and 30, the function will return the list ["even", "odd", "odd", "odd", "even"].arrow_forward
- The chapter is nested lists Create code in python using for loops Thanks!arrow_forwardIn this lab, we will practice the use of arrays. We will write a program that follows the steps below: Input 6 numbers from the user user inputs numbers one at a time Loop continuously until the exit condition below: ask the user to search for a query number if the query number is in the list: reports the first location of the query number in the list, change the number in that position to 0, show the updated list if the query number is not in the list: exit the loop You must write at least one new function: findAndReplace(array1,...,query) – take in an array and query number as input (in addition to any other needed inputs); it will return the first location of the query number in the list (or -1 if it is not in the list) and will change the number at that location to 0. You may receive the number inputs and print all outputs in int main if you wish. You may report location based on 0-indexing or 1-indexing (but you need 0-indexing to access the array elements!).arrow_forward*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_forward
- When 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_forwardDevelop 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
- In python don't import librariesarrow_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_forwardPython programming only NEED HELP PLEASEarrow_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