Sunteți pe pagina 1din 5

IT104 Introduction to Computer Programming

LB9 1

Name: James Espinoza


Lab Task LB9.0
Repetition Structures II
Objectives
1. Create computer programs that can do repetitive processing. 1.1 Evaluate the counter-controlled For loops. 1.2 Use sentinel values in creating computer programs. 1.3 Evaluate nested loops.

Lab 6.4, page 115: Programming Challenge 1 Average Test Scores


Write the Pseudocode, Flowchart, and Python code for the following programming problem. Write a program that will allow a teacher to calculate the average test score for a certain number of students. The teacher can enter the number of students who took the test, and then the score for each student. Your program will then calculate the average score and print out the results. Your program must use the appropriate loop, modules, and run multiple times for different sets of test scores. Your sample output might look as follows: How many students took the test: 9 Enter their score: 98 Enter their score: 78 Enter their score: 99 Enter their score: 92 Enter their score: 87 Enter their score: 100 Enter their score: 88 Enter their score: 81 Enter their score: 79 The average test score is 89 Do you want to end program? (Enter no to process a new set of scores): yes

The Pseudocode 1. Module main () 2. Declare Int Count 3. Declare Int total 4. Declare Int studentCount 5. Declare Int score 6. Declare Int total 7. Declare Int average

LB9 2 Week Nine Lab Exercise 8. //While statement will begin 9. WHILE True 10. //Will have the user input how many took the test. 11. Display How many students took the test: 12. Input studentCount 13. count = 0 14. total = 0 //Will set up the needed times for the user to input the scores 15. WHILE count < studentCount: 16. //Has the users input the scores & displays the average test scores 17. Display Enter their score: 18. Input score 19. total = total + score 20. count=count+1 21. average = averageScore 22. Display The average test score is,average 23. Display Do you want to end the program? (Enter no to process new set of scores) 24. //Will calculate the average of the scores to return to the main module. 25. Def averageScore (scoreTotal, count): 26. Average = scoreTotal / count 27. Return average 28. 29. Main()

IT104 Introduction to Computer Programming

LB9 3

The Flowchart

LB9 4 Week Nine Lab Exercise The Python Code #James Espinoza #February 14 #Lab 9 #This program will use the while function. def main(): #ask the user how many students took the test. while True: studentCount= int(raw_input("How many students took the test:")) count= 0 total= 0 #Will set up the required times it is needed for the user to input scores & display the average of scores. while count < studentCount: score = int(input("Enter their score: ")) total = total + score count=count+1 average = averageScore(total,studentCount) print "The average test score is",average endProgram = raw_input("Do you want to end the program? (Enter no to process a new set of scores):") if endProgram=='yes': break #Will calculate the average of the student scores and return it to the main def averageScore(scoreTotal,count): average = scoreTotal/count return average main()

IT104 Introduction to Computer Programming


Completing the Lab

LB9 5

1. Ensure you have completed all of the tasks required for this lab. 2. Save your lab worksheet and your Raptor and Python files to your instructors network share. There
should be a total of three files saved.

3. Here is what you need to be able to save your work on your instructors network share:
\\10.46.108.76 Username: student Password: P@ssw0rd Users Public IT104 <your_name> WeekNine

4. This lab is due by the end of class.

S-ar putea să vă placă și