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, 23.06.2019 00:40
Consider the following statements: struct nametype{string first; string last; }; struct coursetype{string name; int callnum; int credits; char grade; }; struct studenttype{nametype name; double gpa; coursetype course; }; studenttype student; studenttype classlist[100]; coursetype course; nametype name; mark the following statements as valid or invalid. if a statement is invalid, explain why.a.) student.course.callnum = "csc230"; b.) cin > > student.name; c.) classlist[0] = name; d.) classlist[1].gpa = 3.45; e.) name = classlist[15].name; f.) student.name = name; g.) cout < < classlist[10] < < endl; h.) for (int j = 0; j < 100; j++)classlist[j].name = name; i.) classlist.course.credits = 3; j.) course = studenttype.course;
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
The basic work area of the computer is it screen that you when you first fire up your computer
Answers: 1
question
Computers and Technology, 23.06.2019 16:00
Kenny works with an it company. his company is about to launch new software in the market. he has to ensure that this new software is functional and meets all of the quality standards set up at the planning stage. which job profile is kenny likely to have? kenny is likely to have the job profile of a blank .
Answers: 2
question
Computers and Technology, 24.06.2019 13:00
Which best describes the condition under which the unicode output is the same as plain text ?
Answers: 1
You know the right answer?
Summary In this graded assignment, you will write Python programs that use loops to implement vario...
Questions
Questions on the website: 13722363