In Python you can do better than using
case or
switch. Use a dictionary:
choice = int(raw_input('Type a number between 0 and 9: '))
choices = {1: 'number 1',
2: 'number 2',
3: 'number 3',
4: 'number 4',
5: 'number 5',
6: 'number 6',
7: 'number 7',
8: 'number 8',
9: 'number 9'}
print choices.get(choice, 'The number must be between 0 and 9')The
get method of the dictionary returns the element which index is given in the first parameter. If it is not found it returns the second parameter.
A dictionary is shorter and can be created and modified in runtime while
case and
switch statements are hard coded.