name =input("please input your username : ")#input输入的内容是字符串,若要整型或其他数据类型,则需要做相应的转换!!
age =input("please input your age : ")
hometown =input("please input your hometown : ")print("Hello ",name+'!!!',"\nyou have ", age ,"years old","\nyou came from",hometown)# please input your username : 山药# please input your age : 18# please input your hometown : 武当山# Hello 山药!!! # you have 18 years old # you came from 武当山
二、格式化输出
# 将用户的姓名、年龄、工作、爱好 ,然后打印成以下格式------------ info of 山药 -----------
Name : 山药
Age :22
job : 制作山药
Hobby: beautiful and sex girl
------------- end -----------------#只需要把要打印的格式先准备好, 由于里面的 一些信息是需要用户输入的,你没办法预设知道,因此可以先放置个占位符,再把字符串里的占位符与外部的变量做个映射关系就Ok
name =input('Name:')
age =int(input('Age:'))
job =input('Job:')
hobbie =input('Hobbie:')
info ='''
-------------------info of %s ------------------- # 这里的每个%s就是一个占位符,本行的代表 后面拓号里的 name
Name : %s
Age : %d #%d,是数字占位符
Job : %s
Hobbie : %s
-------------------end--------------------------- # 这行的 % 号就是 把前面的字符串 与拓号 后面的 变量 关联起来
'''%(name,name,age,job,hobbie)print(info)#结果:
Name:山药
Age:18
Job:制作山药
Hobbie:beautiful and sex girl
-------------------info of 山药 -------------------
Name : 山药
Age :18
Job : 制作山药
Hobbie : beautiful and sex girl
------