Python Tour 2 Type C Programming Practice
Python Tour 2 Type C Programming Practice
Question 1:
Write a program that prompts the user to enter a phone number consisting of exactly 10 digits and two
dashes (-).
The dashes must appear after the area code (first 3 digits) and after the next 3 digits.
Example: 017-555-1212.
phNo = input("Enter the phone number: ") # Prompt user for phone number
if length == 12 and phNo[3] == "-" and phNo[7] == "-" and phNo[:3].isdigit() and phNo[4:7].isdigit() and
phNo[8:].isdigit():
else:
-------------------------------------------------------------------
Question 2:
Write a program that prompts the user to type some sentences followed by "Enter".
It should then print the original sentences and display the following statistics:
- Number of words
for ch in str:
spaceCount += 1
alnumCount += 1
# Calculate percentage
print("Original Sentences:")
print(str)
-------------------------------------------------------------------
Question 3:
Write a program that takes two lists L and M of the same size and adds their elements together to form a new
list N.
for i in range(len(L)):
N.append(L[i] + M[i]) # Add corresponding elements
print("List N:")
print(N)
-------------------------------------------------------------------