Exercises on break, continue, and in statements
--D. Thiebaut 07:58, 25 October 2011 (EDT)
Contents
Exercise 1
- Given the list
L = [ 1, 10, 20, 5, 100, 110, 21, 500 ]
- How can we use Python to detect if there exists a number in L that is larger than, say, 50, and record that value in a variable?
Exercise 2
- Ask the user to enter an unspecified number of positive integers, add them to a list, and stop when the user enters -1. At most 100 integers can be entered.
Exercise 3
- Given a list L = [ 1, 10, 20, 5, 100, 110, 21, 500 ], create a new list of the even numbers contained in L.
Exercise 4
- Ask the user for a name and indicate whether this name is one of the 7 dwarves from Snow White.
seven = [