Search code examples
python-3.xformat-stringtitle-case

I'm not getting any output in the correct code (2nd code)?


Hi and thanks in advance for any help.

Here is the code that works with the proper output.

first_name="ada"
last_name="lovelace"
full_name=f"{first_name} {last_name}"
message=(f"Hello, {full_name.title()}!")
print(message)

Here is the similar code with no output...and I can't figure out why?

first_name="ada"
last_name="lovelace"
full_name=f"{first_name} {last_name}"
print(full_name)

I know it is correct coding based on the teacher's response but can't figure out why?

Thank you for any help!


Solution

  • You forgot to add .title() to your string formatting request.

    You can do either:

    # to get both capitalized add .title() twice here at "full name".
    
    first_name="ada"
    last_name="lovelace"
    full_name=f"{first_name.title()} {last_name.title()}"   
    print(full_name)
    

    or:

    
    # to get both capitalized add .title() once here at "message".
    
    first_name="ada"
    last_name="lovelace"
    full_name=f"{first_name} {last_name}"
    message=(f"{full_name.title()}")
    print(message)