Reference no: EM132356510
Question
When people enter phone numbers, they typically enter it in a few different formats:
(919)866-5555
919-866-5555
9198665555
Write a program to strip all occurrences of these characters: '(', ')' and '-'. Also, strip all the leading and trailing whitespace characters. Display the stripped phone number. The following are a few examples:
Enter phone number: (919)866-5555
Phone number with extra characters stripped: 9198665555
Enter phone number: 919-866-5555
Phone number with extra characters stripped: 9198665555
Enter phone number: 9198665555
Phone number with extra characters stripped: 9198665555
[Hint: to delete a string, you can replace it by an empty string]
Save your Python program in a file named Lab13P1.py. Submit the file to Blackboard for credit.
Problem 2
All oranges sold in a grocery store have a 4-digit product code. If the rightmost digit is '4', the orange is from California. If the rightmost digit is '7', the orange is from Florida. For example, an orange with product code '8124' is from California. An orange with product code '6547' is from Florida. Write a program to do the following:
(a) Ask the user to enter the 4-digit code of an orange.
(b) Strip all the leading and trailing whitespace characters from the code.
(c) Test whether the code consists of only numeric digits. If it is not, display an error message.
(d) Test whether the code has exactly 4 characters. If it has more or fewer than 4 characters, display an error message.
(e) Test the rightmost digit. If it is '4', display 'This orange is from California'. If it is '7', display 'This orange is from Florida'. If it is something else, display 'The last digit must be 4 or 7'.
The following are three examples.
Enter product code: 12X45
Product code must consist of digits only.
Product code must not be longer or shorter than 4 characters.
The last digit must be 4 or 7
Enter product code: 0824
This orange is from California
Enter product code: 5237
This orange is from Florida
Save your Python program in a file named Lab13P2.py. Submit the file to Blackboard for credit.
Problem 3
Course codes in a community college consist of two parts: subject and course number. Subject must consist of 3 letters while course number must consist of 3 digits. For example, in the course code 'CIS115, subject is 'CIS', and course number is '115'. Write a program to do the following:
(a) Ask the user to enter a course code.
(b) Strip all the leading and trailing whitespace characters from the code. Display the stripped code.
(c) Test whether the course code is valid. If the course code does not follow the rules described above, display an error message. Otherwise, separate subject from course number and display them separately.
The following are four examples.
Enter course code: CIS115
Subject: CIS
Course number: 115
Enter course code: CIS1155
You have entered an invalid course code
Enter course code: CS2567
You have entered an invalid course code
Enter course code: CIS25K
You have entered an invalid course code