Per the instructions below, I need to ask for a user name,capitalize the name then remove leading or trailing spaces.
Everything works fine until I test for the stripcondition. If I add leading spaces to the input function, thefirst letter of the name is not capitalized with the capitalizefunction.
Why would this happen and what's the best way to correctthis?
Thanks for your help.
Instructions:
Here is my code:
name = input("Enter your name: ")print(name)
name = name.capitalize()print(name)
name = name.strip()print(name)
output without leading spaces in theinput():
Enter your name: heatherheatherHeatherHeather
output with 3 leading spaces in theinput():
Enter your name: heather heather heatherheather
Per the instructions below, I need to ask for a user name, capitalize the name then remove leading or trailing spaces. E
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am