AMS 209: HW 4: Problem 5ΒΆ

 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
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# coding: utf8

'''
Created on October 31st, 2017

@author: Geetanjali
'''

def print_yourName(name_list, notReverse = True):
	"""
	:param name_list: a list of two elements: first name and last name
	:param notReverse: optional argument with default value True. 
	:return: doesn't return anything. Prints first name and last name with the initial letter capitalized. When notReverse is True, it prints first name followed by last name with a space in between. When notReverse is False, it prints the last name followed by the first name, with a comma and space in between
	"""

	first_name = ""
	last_name = ""
	
	first_name = first_name + name_list[0][0].upper()
	last_name = last_name + name_list[1][0].upper()

	for i in range(1, len(name_list[0])):
		first_name = first_name + name_list[0][i]

	for i in range(1, len(name_list[1])):
		last_name = last_name + name_list[1][i]

	if(notReverse):
		print(first_name+" "+last_name)
	else:
		print(last_name+", "+first_name)


if __name__ == '__main__':
	name_list = []

	first_name = input("Enter your first name: ")
	name_list.append(first_name)
	last_name = input("Enter your last name: ")
	name_list.append(last_name)

	print_yourName(name_list)
	print_yourName(name_list, False)