笨办法学Python3 习题14 提示和传递

知识点:

int(input(">"))// 检验用户输入的值是否为整数

 

脚本运行内容:

  • 系统模块导入参数变量
  • 解包参数变量(脚本变量,人名变量)
  • 提示符赋值给变量1
  • 打印提问,用到格式化方式
  • 用户输入上一行问题的回答,回答赋值给变量
  • 打印 用户回答的信息变量
 1 from sys import argv          # 从 系统模块 导入 参数变量
 2 script, user_name = argv      # 将 参数变量 解包,依次赋值给 左边的变量
 3 prompt = ">"                  # 将 > 符号转换字符串 赋值给 提示变量
 4 
 5 print("Hi {} , I'm the {} script.".format(user_name, script))  # 打印 你好某某,我是XX脚本//一种格式写法
 6 print(f"Hi {user_name}, I'm the {script} script.")             # 打印 同上 ,另一种格式化写法
 7 print("I'd like to ask you a few questions.")                  # 打印 我需要问你几个问题
 8 print(f"Do you like me {user_name}?")                          # 打印 你喜欢我吗 某某?
 9 likes = input(prompt)                                          # 弹出提示符,需要用户输入值,再赋值给变量like
10 
11 print(f"Where do you live {user_name}?")                       # 打印 你住在哪里 某某?
12 lives = input(prompt)                                          # 弹出提示符,需要用户输入值,再赋值给变量lives
13 
14 print(f"How old are you {user_name}?")      # 打印 你多大了 某某                  
15 age = int(input(prompt))                    # 需要用整数检验数字,用户输错可报错,弹出提示,用户输入,赋值变量
16 
17 print("What kind of computer do you have?") # 打印 你的电脑是什么样的?
18 computer = input(prompt)                    # 弹出提示,用户输入,赋值变量
19 
20 print(f"""                                   
21 Alright, so you said {likes} about liking me.  
22 You live in {lives}. Not sure where that is.
23 You're {age} years old.
24 And you have a {computer} computer. Nice.
25 """)
26 
27 # 打印  (使用三对引号可以方便任意排列语句)
28 # 好吧,所以你XX喜欢我的
29 # 你生活在某某地.不确定在哪里
30 # 你是X岁了
31 # 还有你有一台XX电脑. 很好

 

PS C:\Users\Administrator\lpthw> python ex14.py biandou
Hi biandou , I'm the ex14.py script.
Hi biandou, I'm the ex14.py script.
I'd like to ask you a few questions.
Do you like me biandou?
>yes
Where do you live biandou?
>china
How old are you biandou?
>25
What kind of computer do you have?
>white

Alright, so you said yes about liking me.
You live in china. Not sure where that is.
You're 25 years old.
And you have a white computer. Nice.

 

posted @ 2023-10-03 11:40  萹豆  阅读(18)  评论(0编辑  收藏  举报