python习题14
Posted shadowyuriya
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python习题14相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章