Computers and Technology
Computers and Technology, 21.07.2020 14:01, keaisad12

Summary In this graded assignment, you will write Python programs that use loops to implement various algorithms.
Learning Outcomes
In completing this assignment, you will:
• Gain more experience converting an algorithm expressed using flowchart to one implemented in a Python program.
• Write a Python program using loops
Description
In a previous assignment in this course, you were asked to draw a flowchart for an algorithm that finds the two smallest items in a list, and then another assignment asked you to convert that flowchart to pseudocode.
Here is a pseudocode implementation of that algorithm:
1. min1- list
2. min2 - list,
3. for each item in list
4. if item 5. then if min1 6. then min2
7. else mint
8. else if item 9. then min2
10. output: min1, min2 item item item
Now, implement the algorithm in Python so that it correctly sets the values of min1 and min2 which should hold the two smallest values in the list, though not necessarily in that order.
In the code below, we have provided a list called "list" and initialized min 1 and min2 to hold the first two elements. Write your code starting at line 5 (you can remove the comments starting at line 6, and may need more space than what is provided), and be sure that the values of min1 and min2 are correctly set before the code reaches the "return (min1, min2)" statement on line 11.
As in the previous assignment, we will be using the Coursera automatic grading utility to test your code once you submit this quiz for grading, and this requires it to be within a function. So be sure that all of the code after line 1 is indented, and that you do not have any code after the "return (min 1, min2)" statement.
Keep in mind that the goal here is to write a program that would find the two smallest values of any list, not just the one provided on line 2. That is, don't simply set min 1 and min2 to-2 and -5, which are the two smallest values, but rather write a program that implements the algorithm from the flowchart and correctly sets min1 and min2 before reaching the return (min1, min2)" statement.
As before, you can test your program by clicking the "Run" button to the right of the code to see the results of any "print" statements, such as the one on line 10 which prints min1 and min2 before ending the function. However, please be sure that you do not modify the last two lines of the code block
1. def test(): # do not change this line!
2. list = [4, 5, 1, 9, -2, 0, 3, -5] # do not change this line!
3. min1 = list[0]
4. min2 = list[1]
5.
6. #write your code here so that it sets
7. #min1 and min2 to the two smallest numbers
8. # be sure to indent your code!
9.
10. print(min1, min2)
11. return (min1, min2) # do not change this line!
12. # do not write any code below here
13.
14. test() # do not change this line!
15. # do not remove this line!
Hints: The Python code for this algorithm is very similar to the pseudocode! Just be sure you are using the correct syntax. As in previous activities, don't forget that you can use the "print" function to print out intermediate values as your code is performing operations so that you can see what is happening

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:00, hannahliebl2000
What is the largest decimal number that can be represented by a binary number with 4 place values? (remember, each place in a binary number has a value of a power of 2, starting in the ones place with 20.)
Answers: 3
image
Computers and Technology, 22.06.2019 18:00, Geo777
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
image
Computers and Technology, 24.06.2019 11:30, AnwarWeirdLol8811
Why is body language an important factor in a business meeting
Answers: 1
image
Computers and Technology, 24.06.2019 13:00, giulissaf
Append and make table queries are called queries. select complex simple action i think action
Answers: 1
Do you know the correct answer?
Summary In this graded assignment, you will write Python programs that use loops to implement vario...

Questions in other subjects:

Konu
Health, 04.12.2020 22:00
Konu
English, 04.12.2020 22:00
Konu
Mathematics, 04.12.2020 22:00
Konu
Mathematics, 04.12.2020 22:00