Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not the expected outcome
#1
I am having difficulty getting the expected outcome. I'm working exercises in a Python book. I would like: as soon as a person enters their first and last name for the message to appear (Hello, formatted name). What have I done incorrectly? I have played around with indentation and checked the author's key. I do not see any errors on my part, but like I said I am not getting the expected outcome.

def get_formatted_name(first_name, last_name):
	full_name = f"{first_name} {last_name}"
	return full_name.title()
# This is an infinite loop until conditions are added.
while True:
	print(f'\nPlease tell me your name:')
	print("(enter 'q' at any time to quit)")
	
	f_name = input("First name: ")
	if f_name == 'q':
		break
	
	l_name = input("Last name: ")
	if l_name == 'q':
		break

formatted_name = get_formatted_name(f_name, l_name)
print(f"\nHello, {formatted_name}!")
Reply
#2
You have a loop that can only be exited by setting either the first or the last name to "q".

If neither name is "q", the loop restarts and you never apply the formatting function.

You could ask to quit in a third question, or you could rearrange the logic.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  outcome 0 but impossiblenumbers change bntayfur 1 1,483 Jul-05-2020, 09:05 PM
Last Post: Yoriz
  Python program that list all possible football outcome combinations lukorir 5 8,865 Oct-17-2019, 04:05 AM
Last Post: steve_shambles
  no outcome is printing helpme 2 2,275 Mar-07-2019, 02:15 PM
Last Post: helpme

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020