Per the instructions below, I need to ask for a user name, capitalize the name then remove leading or trailing spaces. E

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Per the instructions below, I need to ask for a user name, capitalize the name then remove leading or trailing spaces. E

Post by answerhappygod »

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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply