标签:alt 字符串 name 用户 python 输出 print 否则 logs
格式化输出格式:
name = input("name:") age = input("age:") job = input("Job:") salary = input("salary:") msg = """ --------- info of %s ------------- Name = %s Age = %s Job = %s Salary = %s """ %(name,name,age,job,salary) print(msg)
上图%s是一个字符串占位符,每一个占位符对应着每个字符串的值,顺序不能乱一一对应。
输出结果如下:
判断用户输入整数是否为数字
name = input("name:") age = int(input("age:")) job = input("Job:") salary = input("salary:") if salary.isdigit(): #长得像不像数字如,‘200d‘,‘200‘ 如果是执行salary = int(salary) salary = int(salary) else:#否则输出 print("must input dight") print("must input digit") #如果否则条件执行为 exit(must input digit) 那么输出结果为 退出程序提示 must inpput digit msg = """ --------- info of %s ------------- Name = %s Age = %s Job = %s Salary = %s You will be retire %s year """ %(name,name,age,job,salary,65-age) print(msg)
输入 Salary: 20000d
输入结果
标签:alt 字符串 name 用户 python 输出 print 否则 logs
原文地址:http://www.cnblogs.com/ngya/p/6939848.html