Lab 5: Loops
Remember, before running each program type:
scl enable python33 bash
Programs
Find the Max!
To practice using lists and for loops, you are going to ask the user for integer elements and then find the maximum of the elements entered by the user. (Do not use any list methods other than .append()).
Steps to complete this program:
- Initialize an empty list to store users values.
- Obtain values from the user.
- Traverse through the list to find the max.
This program should work no matter how many values the user wants to enter
Sample output code:
Enter a list values and I will find the maximum!
Enter a number or 'q' to find the max of the list: 2
Enter a number or 'q' to find the max of the list: 1
Enter a number or 'q' to find the max of the list: 35
Enter a number or 'q' to find the max of the list: -5
Enter a number or 'q' to find the max of the list: 10
Enter a number or 'q' to find the max of the list: 104
Enter a number or 'q' to find the max of the list: q
The maximum is 104!
Reversing a string!
In this program, you will ask user for a string and then reserve the string and print the output. Do not use any python built in list methods other than .append().
Sample output code:
Enter a String to Reverse: Comp Sci Rocks!
!skcoR icS pmoC
| |