CSC111 While Loop Exercises
--D. Thiebaut 09:43, 10 November 2011 (EST)
revised --D. Thiebaut (talk) 21:55, 16 February 2014 (EST)
Loop Exercises
- Exercise 1
- Write a Python program that asks the user to enter a number that is greater than 0. The function will keep on asking the user for the number until it is valid. The function will return the number.
- Exercise 2
- Write a Python program that asks the user to respond by 'Y', 'y', 'yes', 'YES' or 'N', 'n', 'no', 'NO'. The function keeps on asking until the user enters the correct information. The function will return True if the user entered Yes, and False otherwise.
- Exercise 3
- Write a Python program that reads lines from a file until it finds a line that contains a particular string. The function receives the name of the file, and the string.
- Exercise 4
- Write a program that reads a character for playing the game of Rock-Paper-Scissors. If the character entered by the user is not one of 'P', 'R' or 'S', the program keeps on prompting the user to enter a new character.
- Make the program accept inputs until one player's score is more than 3 points ahead of the other.