Slow Poke Slow Poke - 1 month ago 7
Python Question

How do I accommodate user into that is entered in lower case?

My Goal:
Your program should accommodate the end user inputting a team name in lower case.

Assignment rules:
Use the string methods in Chapter 9 to capitalize the first letter of each word of the input. Build a function for this. Do not use other Python methods (list title or others) you might find, only those in our book!

if i use the .title() at the end of the user input it works fine but according to the instructions I am not allowed to use that function.......which is where I become lost....

Enter the name of a team: new york yankees
The New York Yankees have won the world series 27 times


if I .capitalize() I only get the first letter of the user input capped

`Enter the name of a team: new york yankees
The New york yankees have never won the world series.`


----------On proper input----------------

Enter your choice: 1
Enter the name of a team: New York Yankees
The New York Yankees have won the world series 27 times.


---------End Proper input---------------

--------On lower case input-------------

Enter your choice: 1
Enter the name of a team: new york yankees
The new york yankees have never won the world series.


--------End lower case input-----------

-------Desired output--------------

Enter your choice: 1
Enter the name of a team: new york yankees
The new york yankees have won the world series 27 times.


-------End desired output------------

-------My code---------------

# Enter your team
team = input('Enter the name of a team: ')


---------end my code---------

Answer

If we don't allow to use title() and capitalize(), you can start with "splitting" and "joining":

In [1]: s = "new york yankees"

In [2]: " ".join([word[0].upper() + word[1:] for word in s.split(" ")])
Out[2]: 'New York Yankees'

Not sure if all of that I've used is allowed in your case.

Comments