CSC111 Exercises on Loops

From dftwiki3
Revision as of 14:23, 30 March 2010 by Thiebaut (talk | contribs) (Created page with '==Loop Exercises== ;Exercise 1 : Write a function that asks the user to enter a number that is greater than 0. The function will keep on asking the user for a number until the …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Loop Exercises

Exercise 1
Write a function that asks the user to enter a number that is greater than 0. The function will keep on asking the user for a number until the number is correct. The function will return the number.
Exercise 2
Write a function 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 function that reads lines from the file until it finds a line that contains a particular string. The function receives the name of the file, and the string.
Exercise 4
Pi can be computed by adding the following terms:

Pi expansion.png