Python > Assignment #2: Catalogue

Deadline: Tue 04. 10. 2016, 07:47 CET

Assignment [2pts]: Write a short script that prompts the user for a name, and then transforms the supplied name into a form used for filing, consisting of:

Name: tomas kuzma
Filed as: KUZMA, Tomas

Name: saMOT AmzuK
Filed as: AMZUK, Samot

Solution:

line  = input('Name: ')
words = line.split()

first = words[0].title()
last  = words[1].upper()

print('Filed as: ' + last + ', ' + first)

Bonus [1pts]: Make the script handle multiple “first” names correctly, that is output them properly capitalized in the original order.

Name: to mas kuzma
Filed as: KUZMA, To Mas

Solution

line  = input('Name: ')
words = line.split()

last  = words[-1].upper()
rest  = [x.title() for x in words[:-1]]

print('Filed as: ' + last + ', ' + ' '.join(rest))