-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input_parser
34 lines (34 loc) · 1.24 KB
/
Input_parser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def getName():
name = input("Enter your name as 'First Middle Last: ")
names = name.split()
if len(names) == 3:
return [part.capitalize() for part in names]
else:
print("Invalid input")
return getName()
#--------------------------------------------------------
def getPhoneNum():
while True:
number = input("Please insert phone #, for example: 5188284181: ")
if len(number) == 10:
return number
elif len(number) > 10:
print("Too many digits - please reenter")
elif len(number) < 10:
print("Insufficient length - please reenter")
#-------------------------------------------------------
def parseName(names):
first, middle, last = names
initials = [name_part[0] for name_part in names]
return first, middle, last, initials
#-------------------------------------------------------
def display():
names = getName()
phone = getPhoneNum()
first, middle, last, initials = parseName(names)
print("You entered: ", names)
print("Your initials are: ", initials)
print('\n')
print("Displayed with last name first: ", last + "," + first + "," + middle[0])
print("Your phone number is: " + "(" + phone[:3] + ")" + phone[3:6] + "-" + phone[6:])
display()