In: Computer Science
PYTHON
Write a program for an event organizer. The code can be as short as 7 lines; 9 lines are good enough!
a) Request the organizer to enter a participant’s full name in a single input. The input can take two different formats: i. l_name, f_name [1.5 pts] ii. f_name l_name [1.5 pts] b) Print a customized greeting message using the first name, regardless of the formats: “Dear f_name, welcome to the party!” with only the 1 st letter of f_name in upper case.
Hint 1: Try to work on one form, at a time. After figuring out how to do both, add an if statement.
Hint 2: Just need to use in, len(), .find() and, of course, input().
code:
# Taking full name as one string
s = input("Enter string: ")
# checking whether "," is in string
if "," in s:
ind = s.find(",") # finding index of "," in
string
f_name = s[(ind+1):len(s)] # Then first name is
from comma index to last index
else:
ind = s.find(" ")
f_name = s[0:ind]
# Printing the output string
print("Dear "+f_name+", welcome to the party!")
# They are only 8 lines in the program and i have used only .find(), in
OUTPUT