笨方法学python 习题14
提示和传递
- 学习目标:
- 代码如下:
- 结果输出
- 巩固练习
- 1. 将prompt变量改成完全不同的内容再运行一次
- 2. 再加一个参数。
- 结果输出:
- Tips:
学习目标:
使用argv()和input()
使用input(),利用>作为提示符
了解Zork和Adventure两款游戏
代码如下:
from sys import argvscript,Marry = argv,'Marry'
prompt = '>'
print(f"Hi {Marry},I'm the {script} script.")
print("I'd like to ask you a few questions.")
print(f"Do you like me ? {Marry}")
likes = input(prompt)print(f"Where do you live? {Marry}")
lives = input(prompt)print("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.
""")
结果输出
Hi Marry,I'm the ['D:/Bella/ex14.py'] script.
I'd like to ask you a few questions.
Do you like me ? Marry
>Yes
Where do you live? Marry
>San Francisco
What kind of computer do you have?
>Tandy 1000
巩固练习
1. 将prompt变量改成完全不同的内容再运行一次
from sys import argvscript,Marry = argv,'Marry'
aa = '>'
print(f"Hi {Marry},I'm the {script} script.")
print("I'd like to ask you a few questions.")
print(f"Do you like me ? {Marry}")
likes = input(aa)print(f"Where do you live? {Marry}")
lives = input(aa)print("What kind of computer do you have?")
computer = input(aa)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.
""")######结果输出
Hi Marry,I'm the ['D:/Bella/ex14.py'] script.
I'd like to ask you a few questions.
Do you like me ? Marry
>Yes
Where do you live? Marry
>San Francisco
What kind of computer do you have?
>Tandy 1000Alright,so you said Yes about liking me.
You live in San Francisco. Not sure where that is.
And you have a Tandy 1000 computer. Nice.
2. 再加一个参数。
from sys import argvscript,Marry,Jonn = argv,'Marry','Jonn'
aa = '>'
bb = '>>--'
print(f"Hi {Marry} and {Jonn},I'm the {script} script.")
print("I'd like to ask you a few questions.")
print(f"Do you like me ? {Marry}")
likes = input(aa)
print(f"So do you? {Jonn}")
likes1 = input(bb)print(f"Where do you live? {Marry}")
lives = input(aa)
print(f"So do you? {Jonn}")
lives1 = input(bb)print("What kind of computer do you have?")
computer = input(aa)
print(f"So do you? {Jonn}")
computer1 = input(bb)print(f"""
Alright,so Marry said {likes} about liking me, and Jonn also said {likes} about liking me.
You live in {lives}, and Jonn is live in {lives1}.
And you have a {computer} computer, and Jonn has a {computer1}.Really Nice to me.
""")
结果输出:
Hi Marry and Jonn,I'm the ['D:/Bella/ex14.py'] script.
I'd like to ask you a few questions.
Do you like me ? Marry
>Yes
So do you? Jonn
>>--No
Where do you live? Marry
>Pineapple house
So do you? Jonn
>>--Stone house
What kind of computer do you have?
>HP
So do you? Jonn
>>--MacAlright,so Marry said Yes about liking me, and Jonn also said Yes about liking me.
You live in Pineapple house, and Jonn is live in Stone house.
And you have a HP computer, and Jonn has a Mac.Really Nice to me.进程已结束,退出代码0
Tips:
- 出现报错内容:
syntaxError:invalid syntax
#python环境问题
ValueError: not enough values to unpack
#命名的参数不够
NameError:name 'prompt' is not defined
#拼错了prompt,要么漏掉写了这一行,要么没有创建这个变量
print(f'''
TypeError: 'tuple' object is not callable
#tuple对象是不可调用的
#“[ ]” 和“()”是否用错了,是否误把数据类型当做函数调用
print(f'''
TypeError: 'str' object is not callable
#检查字符串后面加了括号调用
#这行代码上面print()是否正确调用
笨方法学python 习题14相关推荐
- 笨方法学python 习题37
还是在笨方法学python中... 本节的习题是看一下作者列出的python中的各种运算符,尝试来理解这些符号. 在这里,我只列出了一些自己不会的,通过查百度得到得答案,这里来列举一下. (另外有不怎 ...
- 笨方法学python习题4
变量和命名 #笨方法学python_习题4#定义变量 cars = 100 space_in_a_car = 4.0 drivers = 30 passengers = 90#计算 cars_not_ ...
- python数值运算答案_笨方法学Python 习题3:数字和数学计算
数字和数学计算 print("I will now count my chickens") print("Hens",25+30/6) print(" ...
- python手记(游戏) 笨方法学python习题36【持续更新中】
如有意见或其他问题可在下方写下评论或加QQ:1693121186 欢迎一起讨论技术问题! 代码如下: 解说:这是笨方法的习题36,让做一个游戏.我会持续更新,如果想复制玩玩的同学,请别将主线线人以下的 ...
- 笨方法学Python 习题 42: 对象、类、以及从属关系
有一个重要的概念你需要弄明白,那就是"类(class)"和"对象(object)"的区别.问题在于,class 和 object 并没有真正的不同.它们其实是同 ...
- python38使用_笨方法学Python 习题38:列表的操作
列表的操作: 这里先复习一下之前遇见过的函数:split()通过指定分隔符对字符串进行切片,如果参数num有指定值,则仅分隔num个子字符 str.split(str="", nu ...
- 笨方法学python 习题26
习题26 python:3.9 首先我不知道为什么书中的网站打不开,一直是404,所以我就去网上涨了源代码,如下 def break_words(stuff):"""Th ...
- 笨方法学python 习题34
习题34 python:3.9 animals = ['bear','python','peacock','kangaroo','whale','platypus']print ("The ...
- 笨方法学python 习题29-31
if & else 习题29 - if语句 代码如下: 结果输出: Tips: if语句是什么?有什么用处? +=是什么意思? 习题30 else和if 代码如下: 结果输出: Tips: 习 ...
最新文章
- ext 动态赋值text_JQuery中html,val,text-取值赋值的区别-
- Tomcat--HTTPS的简单应用
- 深度 | 用代码构建机器心智,我们离这个目标还有多远?
- c++项目源码_C/C++学习日记:用C++制作餐饮管理系统(附源码),可以用来做毕设的项目!...
- HUE 打开 WorkFlow异常 Operation category READ is not supported in state standby
- Mybatis(4)入门案例中设计模式分析
- Web报表工具FineReport填报界面键盘操作
- Spring MVC 原理 - DispatcherServlet调用完整过程
- 我想去做机器学习 接下来发一些机器学习实战的算法
- 现有VI 创建子VI(LabVIEW软件)
- 12306 抢票助手 Java
- Eclipse设置运行内存大小
- Hadoop安装配置
- MFC Windows 程序设计[253]之美丽的编辑搜索框(附源码)
- 小sun的假期(贪心+逻辑思维)
- 漫游测试之性能测试(5.3-索引分析)
- 微信小程序----API、获取openid、消息订阅
- js邮箱+手机 格式校验
- 原子物理与量子计算机,量子光学与量子信息的实验研究
- MX Player Pro 1.16.5 去广告版 — 安卓视频播放器
热门文章
- android netd分析
- STM32CubeIDE加CubeMX开发二——CudeMX的使用
- HEVC/H.265理论知识(2)——profile、level、tier
- 【飞书集成自建应用教程】
- VS2017无法登录:我们无法刷新此账户的凭证、我们无法添加此账户发送请求时出错、评估期已结束,请登录以解除产品锁定
- 博弈论一 [ 巴什博奕 ]
- ICCV 2019 Vehicle Re-identification with Viewpoint-aware Metric Learning
- 遍历当前目录删除指定的文件夹——批处理
- android 照片特效,Android使用Gallery实现照片拖动的特效
- 【转帖】Photoshop为长腿MM制作拼接效果的照片