
Concept explainers
Maximum of list
Program plan:
- Import the package.
- Define the “Max()” function,
- Make simultaneous assignment to initialize the variables.
- Assign the values return from “len()”.
- Execute while loop when both “lst_1” and “lst_2” have more items,
- Check whether top of “lst_1” is larger,
- If it is “True”, copy that top value into current location in “lst_3”.
- Increment “s1” by “1”.
- Otherwise,
- Copy the top of “lst_2” into the current location in “lst_3”.
- Increment “s2” by “1”.
- Increment “s3” by “1” when element is added to “lst_3”.
- Check whether top of “lst_1” is larger,
- Execute the “while” loop to copy remaining elements from “lst_1”,
- Copy the element.
- Increment “s1” by “1”.
- Increment “s3” by “1”.
- Execute the "while" loop to copy remaining elements from “lst_2”,
- Copy the element.
- Increment “s2” by “1”.
- Increment “s3” by “1”.
- Define the function “merge_Sort()”,
- Assign the initial values for the variable.
- Check whether the number element is greater than 1,
- Split the list into two sub lists.
- Make simultaneous assignment to assign two sub lists using slicing.
- Make recursive calls to sort each sub list.
- Merge the sorted sub list into original list.
- Create empty list.
- Create for loop to iterate “100” times.
- Append the random value to the end of the list.
- Call the “merge_Sort()” function.
- Print the list.

This Python program is to demonstrate a recursive function “Max()” to find the largest number in a list where the largest number is the larger of the first item and the maximum of all the other items.
Explanation of Solution
Program:
File name: “conference.py”
#Import the package
from random import randrange
#Define the function
def Max(lst_1, lst_2, lst_3):
#Make simultaneous assignment
s1, s2, s3 = 0, 0 , 0
#Assign the values return from len()
n1, n2 = len(lst_1), len(lst_2)
'''Execute while loop when both lst_1 and lst_2 have more items'''
while s1 < n1 and s2 < n2:
#Check whether top of lst_1 is larger
if lst_1[s1] > lst_2[s2]:
'''Copy that top value into current location in lst_3'''
lst_3[s3] = lst_1[s1]
#Increment by "1"
s1 = s1 + 1
#Otherwise
else:
'''Copy the top of lst_2 into the current location in lst_3'''
lst_3[s3] = lst_2[s2]
#Increment by "1"
s2 = s2 + 1
#Increment by "1" when element added into lst_3
s3 = s3 + 1
'''Execute the "while" loop to copy remaining elements from lst_1'''
while s1 < n1:
#Copy the element
lst_3[s3] = lst_1[s1]
#Increment by "1"
s1 = s1 + 1
#Increment by "1"
s3 = s3 + 1
'''Execute the "while" loop to copy remaining elements from lst1_2'''
while s2 < n2:
#Copy the element
lst_3[s3] = lst_2[s2]
#Increment by "1"
s2 = s2 + 1
#Increment by "1"
s3 = s3 + 1
#Define the function
def merge_Sort(num):
#Assign the value
n = len(num)
'''Check whether the number element is greater than 1'''
if n > 1:
#Split the list into two sub lists
v = n // 2
'''Make simultaneous assignment to assign two sub lists using slicing'''
nums_1, nums_2 = num[:v], num[v:]
#Make recursive calls to sort each sub list
merge_Sort(nums_1)
merge_Sort(nums_2)
#Merge the sorted sub list into original list
Max(nums_1, nums_2, num)
#Create empty list
lst = []
#Create for loop
for n in range(100):
#Append the random value to the end of the list
lst.append(randrange(1, 1000))
#Call the function
merge_Sort(lst)
#Print the list
print(lst)
Output:
[996, 992, 975, 974, 956, 952, 947, 937, 921, 915, 902, 899, 891, 889, 886, 863, 863, 862, 856, 841, 837, 819, 808, 791, 760, 755, 754, 739, 736, 732, 685, 663, 638, 628, 623, 622, 612, 594, 569, 562, 552, 532, 531, 528, 527, 523, 492, 475, 468, 461, 452, 451, 444, 438, 431, 413, 405, 401, 375, 370, 358, 354, 350, 350, 347, 339, 325, 290, 286, 246, 227, 220, 215, 188, 185, 182, 168, 161, 149, 142, 141, 141, 139, 135, 115, 114, 112, 101, 96, 94, 94, 85, 84, 84, 80, 78, 70, 18, 13, 11]
>>>
Want to see more full solutions like this?
Chapter 13 Solutions
Python Programming: An Introduction to Computer Science
- When using functions in python, it allows us tto create procedural abstractioons in our programs. What are 5 major benefits of using a procedural abstraction in python?arrow_forwardFind the error, assume data is a string and all variables have been declared. for ch in data: if ch.isupper: num_upper = num_upper + 1 if ch.islower: num_lower = num_lower + 1 if ch.isdigit: num_digits = num_digits + 1 if ch.isspace: num_space = num_space + 1arrow_forwardFind the Error: date_string = input('Enter a date in the format mm/dd/yyyy: ') date_list = date_string.split('-') month_num = int(date_list[0]) day = date_list[1] year = date_list[2] month_name = month_list[month_num - 1] long_date = month_name + ' ' + day + ', ' + year print(long_date)arrow_forward
- Find the Error: full_name = input ('Enter your full name: ') name = split(full_name) for string in name: print(string[0].upper(), sep='', end='') print('.', sep=' ', end='')arrow_forwardPlease show the code for the Tikz figure of the complex plane and the curve C. Also, mark all singularities of the integrand.arrow_forward11. Go to the Webinars worksheet. DeShawn wants to determine the number of webinars the company can hold on Tuesdays and Thursdays to make the highest weekly profit without interfering with consultations, which are also scheduled for Tuesdays and Thursdays and use the same resources. Use Solver to find this information as follows: a. Use Total weekly profit as the objective cell in the Solver model, with the goal of determining the maximum value for that cell. b. Use the number of Tuesday and Thursday sessions for the five programs as the changing variable cells. c. Determine and enter the constraints based on the information provided in Table 3. d. Use Simplex LP as the solving method to find a global optimal solution. e. Save the Solver model below the Maximum weekly profit model label. f. Solve the model, keeping the Solver solution. Table 3: Solver Constraints Constraint Cell or Range Each webinar is scheduled at least once on Tuesday and once on Thursday B4:F5 Each Tuesday and…arrow_forward
- Go to the Webinars DeShawn wants to determine the number of webinars the company can hold on Tuesdays and Thursdays to make the highest weekly profit without interfering with consultations, which are also scheduled for Tuesdays and Thursdays and use the same resources. Use Solver to find this information as follows: Use Total weekly profit as the objective cell in the Solver model, with the goal of determining the maximum value for that cell. Use the number of Tuesday and Thursday sessions for the five programs as the changing variable cells. Determine and enter the constraints based on the information provided in Table 3. Use Simplex LP as the solving method to find a global optimal solution. Save the Solver model below the Maximum weekly profit model label. Solve the model, keeping the Solver solution. Table 3: Solver Constraints Constraint Cell or Range Each webinar is scheduled at least once on Tuesday and once on Thursday B4:F5 Each Tuesday and Thursday…arrow_forwardI want to ask someone who has experiences in writing physics based simulation software. For context I am building a game engine, and want to implement physics simulation. There are a few approaches that I managed to find, but would like to know what are other approaches to doing physics simulation entry points from scenes, would you be able to visually draw me a few approaches (like 3 approaces)? When I say entry point to the actual physics simulation. An example of this is when the user presses the play button in the editor, it starts and initiates the physics system. Applying all of the global physics settings parameters that gets applied to that scene. Here is the use-case, I am looking for. If you have two scenes, and select scene 1. You press the play button. The physics simulation starts. When that physics simulation starts, you are also having to update the physics through some physics dedicated delta time because physics needs to happen faster update frequency. To elaborate,…arrow_forwardI want to ask someone who has experiences in writing physics based simulation software. For context I am building a game engine, and want to implement physics simulation. There are a few approaches that I managed to find, but would like to know what are other approaches to doing physics simulation entry points from scenes, would you be able to visually draw me a few approaches (like 3 approaces)?When I say entry point to the actual physics simulation. An example of this is when the user presses the play button in the editor, it starts and initiates the physics system. Applying all of the global physics settings parameters that gets applied to that scene.Here is the use-case, I am looking for. If you have two scenes, and select scene 1. You press the play button. The physics simulation starts. When that physics simulation starts, you are also having to update the physics through some physics dedicated delta time because physics needs to happen faster update frequency.To elaborate, what…arrow_forward
- Male comedians were typically the main/dominant star of television sitcoms made during the FCC licensing freeze. Question 19 options: True False In the episode of The Honeymooners that you watched this week, why did Alice decide to get a job outside of the home? Question 1 options: to earn enough money to buy a mink coat to have something to do while the kids were at school to pay the bills after her husband got laid offarrow_forwardAfter the FCC licensing freeze was lifted, sitcoms featuring urban settings and working class characters became far less common. Question 14 options: True Falsearrow_forwardsolve this questions for me .arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L



