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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:30
Selective incapacitation is a strategy to reduce prison population
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
Jason needs to learn a new web tool. he went through his books to understand more about it. now he wants hands-on experience with using that tool. what would him? jason can use websites where workspace is provided to test the results of your code.
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
Creating "smart interfaces" in all sectors of industry, government, and the public arena is one of the fastest growing hct areas. these interfaces model, interpret, and analyze such human characteristics as speech, gesture, and vision. the field of biometrics, in which humans authenticate themselves to machines, is an area of considerable interest to hct practitioners. fingerprint scans are one of the most frequently used biometric options, and this article, biometric student identification: practical solutions for accountability & security in schools, makes a case for the implementation of fingerprint scans in schools. critique the article, and answer the following questions: according to the author, what are the main benefits of adopting fingerprint scans in schools for student identification? according to the author, what are the main drawbacks of adopting fingerprint scans in schools for student identification? do you agree with the author's assessment of the pl
Answers: 2
question
Computers and Technology, 23.06.2019 19:00
Acompany is hiring professionals for web designing. the firm is small with few resources. they want employees who possess problem-solving skills and can independently carry out responsibilities. which kind of employee should they select?
Answers: 2
You know the right answer?
Summary In this graded assignment, you will write Python programs that use loops to implement vario...
Questions
question
Chemistry, 08.04.2021 17:10
question
Mathematics, 08.04.2021 17:10
question
Mathematics, 08.04.2021 17:10
Questions on the website: 13722361