subject

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

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 21:30, moomoo2233
What’s the process of observing someone actually working in a career that interests you?
Answers: 1
image
Computers and Technology, 21.06.2019 22:40, bartekpiglo
Write an assembly program with the following specifications. a). in the main block, you should have two registers r4 and r5. they should be checked in an infinite loop. if r4 is greater than r5, then the greater subroutine will be called. if r4 is less than r5, then the less subroutine will be called. if r4 equals r5, then no operations will be done
Answers: 1
image
Computers and Technology, 22.06.2019 00:30, bargasdevon123
To insert a column without using commands in any tabs, a user can -click and then click insert column.
Answers: 3
image
Computers and Technology, 23.06.2019 11:00, jolleyrancher78
What are the possible consequences of computer hacking? what is computer piracy? describe some examples. what are the effects of computer piracy? what are the possible consequences of computer piracy? what is intentional virus setting? describe some examples. what are the effects of intentional virus setting? what are the possible consequences of intentional virus setting? what is invasion of privacy? describe some examples. what are the effects of invasion of privacy? what are the possible consequences of invasion of privacy? what is an acceptable use policy and what is the purpose of the acceptable use policy what is intellectual property and how can you use it?
Answers: 1
You know the right answer?
Summary In this graded assignment, you will write Python programs that use loops to implement vario...

Questions in other subjects:

Konu
English, 24.09.2021 01:50
Konu
Mathematics, 24.09.2021 01:50