Computer Science I for majors by James Tam |
Write a Python program that will prompt the user for a valid phone number. The value should only consist of the seven digit phone number (no area code, no spaces, no dashes). You can assume that the user will only enter numeric values. The program should repeatedly ask for a phone number until a value within the valid range has been entered. The first digit of the phone number cannot begin with a zero but may consist of another other number from 1 - 9 e.g., 0123456 IS NOT a valid phone number. The other six digits can consist of values from 0 - 9 e.g. 1, 9999999 IS a valid phone number, e.g.2, 1000000 IS a valid phone number. Once the user does enter a valid phone number then the program should not prompt again but instead should display a brief confirmation message that the value entered was okay e.g., "Thank you valid phone number entered."
Aside from input()/print() and functions to convert types: str(), float(), int(), unless you are told otherwise, you will need to write your own code and cannot use other pre-written Python functions/methods.
Feature |
Marks |
Prompts for phone number |
1 |
Repeats prompt if number outside the valid range (4 marks for checking where it's too low, 4 marks for checking where it's too high) |
8 |
Displays a confirmation message if a valid phone number is entered |
2 |
TOTAL |
11 |
Raw score | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Grade point | 4 | 3.7 | 3.3 | 3.0 | 2.7 | 2.3 | 2.0 | 1.7 | 1.3 | 1.0 | 0.7 | 0 |
Using pre-written Python libraries:
In case you are 'bored' with level of difficulty of this practice exercise and want to something a little more challenging here is a practice exercise that you can work on for extra practice (but it isn't graded): [Harder practice problem]