13、python基础学习-格式化输出

 1 #__author: hlc
 2 #date: 2019/5/25
 3 # 格式化输出
 4 
 5 name = str(input("your name>>>: "))
 6 age = int(input("yuor age>>>: "))
 7 job = str(input("your job>>>: "))
 8 salary = input("your salary>>>: ")
 9 
10 if salary.isdigit():
11     salary = int(salary)
12 else:
13     #print("must input digit")
14     exit("must input digit")
15 
16 msg = '''
17 ------------ info of %s ---------------------
18 Name:%s
19 Age: %d
20 Job: %s
21 Salary: %f
22 --------------  end  ------------------------
23 '''% (name,name,age,job,salary)
24 # %s = string 表示字符串 $d  = digit 表示数字 $f = float 浮点数,约等于小数
25 print(msg)
26 
27 # 输出
28 # C:\python37\python.exe D:/python-note/formatting_out.py
29 # your name>>>: abc
30 # yuor age>>>: 23
31 # your job>>>: IT
32 # your salary>>>: 30000
33 #
34 # ------------ info of abc ---------------------
35 # Name:abc
36 # Age: 23
37 # Job: IT
38 # Salary: 30000.000000
39 # --------------  end  ------------------------

 

posted @ 2019-05-25 17:36  hlc-123  阅读(303)  评论(0编辑  收藏  举报