用户交互和格式化输出
如何格式化输出一组用户刚刚输入好的数据
#!/usr/bin/env python this_year = 2014 name = raw_input("whta is your name?") age = int(raw_input("how old are you?")) sex = raw_input("Your gender?") dep = raw_input("What is your occupation?") information = """User information is as follows Name: %s age : %d sex : %s dep : %s """ print information %(name,age,sex,dep)
定义格式化,并给出各项数值。%s为字符串,%d为数字
输出如图:
[[email protected] ~]# python test.py whta is your name?jia chen how old are you?25 Your gender?male What is your occupation?IT User information is as follows Name: jia chen age : 25 sex : male dep : IT
python2 用户交互和格式化输出
时间: 2024-11-03 05:42:04