An existing practice needs to ask the user's name, age, job, hobbies, and then printed in the following format
More info of Hu ------------ ----------- Name: Pang Hu Age: 22 Job: Program Hobbie: Music ---------- end ----------------- ---
How do you achieve it? You will find that harder to achieve the output format with character mosaic way, so together to learn about new posture
Just format should be printed first ready due to some inside information that require user input, you can not know the default, so you can place the first placeholder, then the string in the placeholder with the outside variables to be a mapping between Jiuhaola
INPUT = name ( " the Name: " ) Age = INPUT ( " Age: " ) Job = INPUT ( " the Job: " ) Hobbie = INPUT ( " Hobbie: " ) info = '' ' --------- --- info of% s ----------- #% s herein each is a placeholder for the back of the extension number of the Bank's name the name:% s # Representative name Age: % s # on behalf of Age the Job:% s # on behalf of the Job Hobbie:% s # represents the Hobbie ------------- ----------------- End '' ' % (name, name, Age, Job,Hobbie) # % is the line number associated with the extension number of the back of the string variable up front Print (info)
% S represents a string is a placeholder, in addition, there% d, digital placeholder,% f placeholder is floating, if the back of the upper age replaced% d, on behalf of you You must only enter numbers
All input received input string is the default format!
To program is not wrong, then how to do it? Simple, you can turn into str int
age = int( input("Age:") )
print(type(age))
Certainly no problem. Conversely, you can turn into a digital string it? May be inevitable,str( yourStr )