Display the stripped phone number

Assignment Help Python Programming
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

Reference no: EM132356510

Questions Cloud

Create a list called readinglist with two books : Define a function called printList that takes in a list as a parameter and prints the entries in the list one entry per line. If the list is empty have program.
Read a four digit decimal integer from the keyboard : Subject Use Python IDLE, select file menu then new file command to edit and debug your program. Write a complete Python program.
How many times each letter of the alphabet was used : Allow the user to type in a sentence to allow the program to perform analytics. Find out how many times each letter of the alphabet was used in useras sentence.
Analyze a comma-separated values file of real estate data : Write a menu driven console program that loads, parses and analyzes a comma-separated values file of real estate data.
Display the stripped phone number : Ask the user to enter the 4-digit code of an orange. Strip all the leading and trailing whitespace characters from the code. Display the stripped phone number.
Write a program to analyze the test scores : An instructor teaches two classes this semester. Recently he gave the same test to both classes. Write a program to analyze the test scores.
Display the array of names and the array of votes to provide : Write a function that accepts the name of an output file and displays the array of names and the array of votes to the provided output file.
Identify and describe one federal public health law : Key Participants in Decision Making - Identify and describe one federal public health law and the key decision makers in getting the law passed
Write a python program to list the data types used in this : Write a Python program to load the exact data into a data frame df2016. Write a Python program to list the data types used in this data frame.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd