首页 > 解决方案 > 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!

标签: python-3.xformat-stringtitle-case

解决方案


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)

推荐阅读