用户输入姓名、年龄、职业、工资后打印信息:
%s 代表字符串 string
%d 代表整数 digit
%f 代表浮点数 flloat
name = input("Name:") age = int(input("Age:")) job = input("Job:") salary = input("Salary:") if salary.isdigit(): #判断长得像不像数字 salary = int(salary) else: print("You must input digit.") exit() #退出程序 print(name, age, job, salary) msg = ‘‘‘ -------------info of %s----------- Name: %s Age: %d Job: %s Salary:%f You will be retired in %s year -------------end------------- ‘‘‘%(name, name, age, job, salary, 65-age) print(msg)
原文:https://www.cnblogs.com/evatan123/p/9190361.html