Ex11, sd3 - formatting and printing variables

Ok, so I did:
city = input("What part of Japan did you visit? ")
answer = "Great, {}".format(city), "is an interesting city!"
print(answer)
And the output I get is:

What part of Japan did you visit? kanazawa
(‘Great, kanazawa’, ‘is an interesting city!’)

If I do:
print("Great, {}".format(city), "is an interesting city!")
it works well.
L.E.
I used an f string instead and it worked. I am just curious how could I print the answer variable using .format()
So I did:
city = input("What part of Japan did you visit? ")
answer = f"Great, {city} is an interesting city!"
print(answer)
and the output:

What part of Japan did you visit? kanazawa
Great, kanazawa is an interesting city!

…and solved it:
city = input("What part of Japan did you visit? ")
answer = "Great, {} is an interesting city!"
print(answer.format(city))
Output:

What part of Japan did you visit? hhh
Great, hhh is an interesting city!

1 Like