Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (50 pts) Define a function that takes two integers x and k as parameters. The function should divide x into k (mostly) equal integers

image text in transcribed

1. (50 pts) Define a function that takes two integers x and k as parameters. The function should divide x into k (mostly) equal integers and combine each of these integers into a list. The function should return this list. The value of k has to be a positive integer; if it isn't, an error message should be displayed. To test your function, read two integers from the user, call the function by passing these two integers as arguments and print the list returned from the function. Warning: You are not allowed to use any built-in functions: you are supposed to compute the result using iterations. Please ent SAMPLE OUTPUT 1 (bold parts are entered by user): the number to be partitioned: 45 Please enter the number of partitions: 10 The partitioning is as follows: [5, 5, 5, 5, 5, 4, 4, 4, 4, 4] SAMPLE OUTPUT 2 (bold parts are entered by user): Please enter the number to be partitioned: 32 Please enter the number of partitions: 4 The partitioning is as follows: [8, 8, 8, 8) SAMPLE OUTPUT 3 (bold parts are entered by user): Please enter the number to be partitioned: -33 Please enter the number of partitions: 8 The partitioning is as follows: (-5, -4, -4, -4, -4, -4, -4, -4] 2. (50 pts) Define a function that takes a list of integers as a parameter. The function should sort the list in ascending order, using the following approach: Iterate through the list, find the minimum element, swap it with the first element. Then iterate through the list (except the first element, which is already sorted), find the minimum element, swap it with the second element, etc. Repeat this process until all elements of the list are in the correct order. The function should not return anything. To test your function, create a list containing 10 integer elements (The values in this list are irrelevant, except they should be integers). Then, call your function by passing this 10-element list as an argument. Finally, print the list (which should be correctly sorted). Warning: You are not allowed to use any built-in functions: you are supposed to compute the result using iterations

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions