Python-练习 12 提示用户

Python-练习 12 提示用户

当你输入 () 的时候,一定要确保输入完整,它们是成对出现的。对于 input 来说,你还可以给用户放一个提示,让他知道该输入什么。你可以把提示的字符串放在 () 里面,就像这样:
y = input(“Name?”)
这个提示告诉用户输入“名字”,然后把结果放到变量 y 里面。通过这种方式你就可以问用户问题然后得
到他输入的答案。

ex12.py

代码

age = int(input("How old are you? "))
height = input(f"You're {age}? Nice. How tall are you? ")
weight = input("How much do you weigh? ")

print(f"So, you're {age} old, {height} tall and {weight} heavy.")

'''-----------------------------------------------------------------------------'''

'''
1. 在 Terminal 里输入 pydoc input ,看看它会说什么。如果你用的是 Windows, 输入
python3.6 -m pydoc input 。
Help on built-in function input in module builtins:
input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.

    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.

    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.

2. 输入 q ,退出 pydoc 。

3. 到网上查查 pydoc 命令的作用。
pydoc是python自带的一个文档生成工具,使用pydoc可以很方便的查看类和方法结构

4. 用 pydoc 读一读关于 open , file , os ,和 sys 的内容;浏览一遍即可,把有意思的东
西记下来。

open:Help on built-in function open in module io:
 open() returns a file object whose type depends on the mode, and
    through which the standard file operations such as reading and writing
    are performed.

os:Help on module os:
    os - OS routines for NT or Posix depending on what system we're on.

sys:
 https://docs.python.org/3.7/library/sys
 该模块提供了一些变量和函数。这些变量可能被解释器使用,也可能由解释器提供。这些函数会影
 响解释器。本模块总是可用的。
 
'''

运行结果

在这里插入图片描述

问题

为什么我每次运行 pydoc 都会收到错误信息: SyntaxError: invalid syntax ?
要么你没在命令行运行pydoc ,要么你先运行了 python3.6,先退出 python3.6 再运行 pydoc 。

为什么我的 pydoc 没有像你的一样暂停?
有时候如果帮助文件很短,一屏足以放下的话, pydoc 就只会把它打印出来。

当我运行 pydoc 的时候我会收到 more is not recognized as an internal 。
一些 Windows 版本没有这个命令,你可以跳过这个小题,需要它的时候在网上搜搜 Python documentation 即可。

为什么我不能用 print(“How old are you?”, input()) ?
你能,只不过 input() 的结果不会被保存到一个变量里,它会以一种奇怪的方式运行。你可以试试,然后试着打印你输入的东西,看看你能不能搞明白为什么它无法运行。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值