Home > other >  Wrote a piece of code, but found that when the output sequence, and expected to you to consult the c
Wrote a piece of code, but found that when the output sequence, and expected to you to consult the c

Time:11-10

Below is a sample code, such as First_name Jimmy, Middle_name is Ken, Last_name is green, but the output is Jimmy green, Ken, don't know where is wrong, also want to consult, I don't write Middle_name here is setting the input q, so if you don't input Middle_name directly press the return key, this code for
how should change?
While True:
Print (" \ nPlease tell me your name: ") # \ n makes both Please tell me your name:
is a line in the front of the SpacesF_name=input (" First name: ")

Print (" if there is no Middle name, please input q ")
M_name=input (" Middle name: ")
If m_name=='q:
L_name=input (" Last name: ")
Formatted_name=get_formatted_name (f_name l_name)
Print (" \ nHello, "+ formatted_name +"!" )
Break
The else:
L_name=input (" Last name: ")
Formatted_name=get_formatted_name (f_name m_name, l_name)
Print (" \ nHello, "+ formatted_name +"!" )
break

CodePudding user response:

 


While True:
The first_name=input (" please enter your first name: ")
Middle_name=input (" please enter your middle name: ")
Last_name=input (" please enter your last name: ")
If middle_name:
Print (" hello "+ first_name, middle_name + last_name)
The else:
Print (" hello "+ +" q "first_name + last_name)

CodePudding user response:

Output order problem, should see you get_formatted_name function of internal operations
 

While True:
Print (" \ nPlease tell me your name: ") # \ n makes both Please tell me your name:
is a line in the front of the SpacesF_name=input (" First name: ")

Print (" if there is no Middle name, please enter the enter ")
M_name=input (" Middle name: ")
If len (m_name)==0:
L_name=input (" Last name: ")
Formatted_name=f_name + l_name
Print (" \ nHello, "+ formatted_name +"!" )
Break
The else:
L_name=input (" Last name: ")
Formatted_name=f_name + m_name + l_name
Print (" \ nHello, "+ formatted_name +"!" )
Break
  • Related