0
#Just defining strings needed for later
Mc = "Mc"
O = "O'"

#What is your name?
name = raw_input('What is your first name?')
name2 = raw_input('What is your last name?')

#Setting up the grammar for all of these weirdly typed names
game = name.lower()
game2 = name2.lower()
lame = game[1:len(game)]
lame2 = game2[1:len(game2)]
Name = game[0].upper() + lame
Name2 = game2[0].upper() + lame2

#For the names with a Mc in it
if Name2[0:1] == "mc" or "MC":
    Last_Name = Mc + Name2[2].upper() + Name2[3:len(Name2)]

#For the names with an O'name in it
elif Name2[0:1] == "O'" or "o'":
    Last_Name = O + Name2[2].upper() + Name2[3:len(Name2)]

#For the regular names
else:
    Last_Name = Name2

#For the liars
if len(Name) + len(Name2) > 25:
    print "STOP LYING!"

#Lets finally print this beast
else:
    print "Welcome " + Name + " " + Last_Name + "!"

This is supposed to format names to print them, and when they have a McLastname, it would fix the capitalization, but when I put input any last name, it replaces the first 2 letters with a Mc, even if the name doesn't start with a mc. If I type in a last name such as Smith, it changes it to McIth. Would there be any way to change this so it would only change the first 2 letters to Mc if the name starts with mc or MC? Thanks.

2 Answers2

0

if Name2[0:1] == "mc" or "MC":

should be

if Name2[0:1] == "mc" or Name2[0:1] == "MC":

Otherwise this if statement is always true because "MC" is true.

Rikka
  • 999
  • 8
  • 19
0

This statement:

 if Name2[0:1] == "mc" or "MC":

is always true. It is the equivalent of saying Is it true the Name starts with "mc" or is "MC" true? But in Python, a non-empty string is always true, so the second part is always true, so the whole thing is always true.

You meant to write:

 if Name2[0:1] == "mc" or Name2[0:1] == "MC":

but could also write

 if Name2[0:1] in ("mc", "MC"):

or

 if Name2[0:1].upper() == "MC":
Larry Lustig
  • 49,320
  • 14
  • 110
  • 160