码迷,mamicode.com
首页 > 其他好文 > 详细

练习14--提示和传递

时间:2020-06-28 09:19:54      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:zed   where   adc   live   san   调用   输入   about   http   

一 主要语法

本次习题的主要语法内容是:用一种不同的方式使用input ,就是让它打印出一个简单的 > 提示符。

  • 具体做法:定义一个提示符变量:prompt = ‘ > ‘
  •                  在某个变量需要输入的时候,调用input函数的方式为:likes = input(prompt)
  •       注意:我们把用户提示符设置成变量 prompt ,然后把它赋给 input 而不是一遍遍地输入它们。现在如果我们想把提示符变成别的东西,只需要在定义prompt变量的时候修改引号内的内容即可

二 代码及运行结果

1 代码:

from sys import argv

script,user_name = argv
prompt =  >>> 

print(f"Hi {user_name},I‘m the {script} script.")
print("I‘d like to ask you a few questions.")
print(f"Do you like me {user_name}?")
likes = input(prompt)

print(f"Where do you live {user_name}?")
lives = input(prompt)

print(f"What kind of computer do you have?")
computer = input(prompt)

print(f"""
Alright, so you said {likes} about liking me.
You live in {lives}.Not sure where that is.
And you have a {computer} computer.Nice.
  """)

2 运行结果

PS E:\3_work\4_python\2_code\02_LearnPythonTheHardWay> python ex14.py Zed
Hi Zed,Im the ex14.py script.
Id like to ask you a few questions.
Do you like me Zed?
 >>> Yes
Where do you live Zed?
 >>> San Francisico
What kind of computer do you have?
 >>> Tandy 1000

Alright, so you said Yes about liking me.
You live in San Francisico.Not sure where that is.
And you have a Tandy 1000 computer.Nice.

 三 游戏

1 zork游戏:https://www.douban.com/group/topic/21962101/

2 Adcenture:https://baijiahao.baidu.com/s?id=1632958318937965675&wfr=spider&for=pc

练习14--提示和传递

标签:zed   where   adc   live   san   调用   输入   about   http   

原文地址:https://www.cnblogs.com/luoxun/p/13200883.html

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