码迷,mamicode.com
首页 > 编程语言 > 详细

python习题14

时间:2018-11-16 01:12:01      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:com   col   变量   inpu   code   argv   字符串   int   参数   

 1 #引入特性
 2 from sys import argv
 3 
 4 #解包
 5 script, user_name = argv
 6 #把用户提示符>(字符串)赋值给prompt
 7 prompt = >
 8 
 9 #把变量user_name、script带入并且打印整句话
10 print(f"Hi {user_name}, I‘m the {script} script.")
11 #打印
12 print("I‘d like to ask you a few questions.")
13 #嵌入并且打印
14 print(f"Do you like me {user_name}?")
15 #首先会出现一个>,再输入内容
16 likes = input(prompt)
17 
18 print(f"Where do you live {user_name}?")
19 lives = input(prompt)
20 
21 print("What kind of computer do you have?")
22 computer = input(prompt)
23 
24 #把之前输入的变量嵌入到字符串里,并且打印
25 print(f"""
26 Alright, so you said {likes} about liking me.
27 You live in {lives}. Not sure where that is.
28 And you have a {computer} computer. Nice.
29 """)

 

将prompt变量改成完全不同的内容再运行一遍

 1 #引入特性
 2 from sys import argv
 3 
 4 #解包
 5 script, user_name = argv
 6 #把用户提示符>(字符串)赋值给prompt
 7 prompt = 我来回答一下:
 8 
 9 #把变量user_name、script带入并且打印整句话
10 print(f"Hi {user_name}, I‘m the {script} script.")
11 #打印
12 print("I‘d like to ask you a few questions.")
13 #嵌入并且打印
14 print(f"Do you like me {user_name}?")
15 #首先会出现一个>,再输入内容
16 likes = input(prompt)
17 
18 print(f"Where do you live {user_name}?")
19 lives = input(prompt)
20 
21 print("What kind of computer do you have?")
22 computer = input(prompt)
23 
24 #分行打印
25 print(f"""
26 Alright, so you said {likes} about liking me.
27 You live in {lives}. Not sure where that is.
28 And you have a {computer} computer. Nice.
29 """)

 

将你的脚本再添加一个参数,并且使用这个参数,格式和ex13.py的first,second = argv 一样

 1 #引入特性
 2 from sys import argv
 3 
 4 #解包模块
 5 script, user_name ,age= argv
 6 #把用户提示符>(字符串)赋值给prompt
 7 prompt = 我来回答一下:
 8 
 9 #把变量user_name、script带入并且打印整句话
10 print(f"Hi {user_name}, I‘m the {script} script,you are {age} old.")
11 #打印
12 print("I‘d like to ask you a few questions.")
13 print("Your age is: ",age)
14 #嵌入并且打印
15 print(f"Do you like me {user_name}?")
16 #首先会出现一个>,再输入内容
17 likes = input(prompt)
18 
19 print(f"Where do you live {user_name}?")
20 lives = input(prompt)
21 
22 print("What kind of computer do you have?")
23 computer = input(prompt)
24 
25 #分行打印
26 print(f"""
27 Alright, so you said {likes} about liking me.
28 You live in {lives}. Not sure where that is.
29 And you have a {computer} computer. Nice.
30 """)

 

python习题14

标签:com   col   变量   inpu   code   argv   字符串   int   参数   

原文地址:https://www.cnblogs.com/shadowyuriya/p/9967030.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!