MONT 105S, Spring 2009

Home | | Course Schedule | | Assignments | | Lecture Notes

Laboratory 5
Due at the end of today's class

Problem 1:
Write a program that asks the user what item they would like to search for and then uses a for loop to search for that item in a list. The program should print out the number of times the item occurs in the list. If there are zero or more than one occurence of the item, the program should add an 's' to the name of the item when it reports the number found.

You should use the following template for your program:

The following are sample outputs of the program:
Sample output 1:

What item would you like to search for? axe
You have 2 axes.

Sample output 2:

What item would you like to search for? shield
You have 1 shield.


Problem 2: Write a program that uses a for loop to sum up all the even numbers from 2 to some high number entered by the user.

You may use the following program template:

The following are sample outputs of the program:
Sample output 1:

This program sums all the even numbers up to a given number.
What is the highest number you would like to add? 6
The numbers are: 
2
4
6
The total is: 12

Sample output 2:

This program sums all the even numbers up to a given number.
What is the highest number you would like to add? 9
The numbers are: 
2
4
6
8
The total is: 20


Problem 3:
Write a program that uses a for loop to multiply the value of each number in a list by 2. You may use the following program template:

The following is the output of the program:
Sample output:

The values in the list are: 
1
3
17
5
6
14
The doubled list is: 
2
6
34
10
12
28

What To Turn In.

A printed listing of the lab programs. Be sure that your name is in the program prologue’s comment section of the program.

Reminder.

Be sure to save a copy of each program on your P:\ drive.