程序员文章、书籍推荐和程序员创业信息与资源分享平台

网站首页 > 技术文章 正文

[oeasy]python062_在python中完成输入和输出_input_print

hfteth 2025-02-04 14:12:39 技术文章 14 ℃

在python中完成输入和输出_input_print

回忆上次内容

  • 上次讲的是
    • input 函数 的参数
    • prompt
    • 提示词
  • 我想写一个程序
    • 输入名字
    • 然后对他说hello
    • 并欢迎
  • 具体怎么写呢?

input.py

  • vim 启动
    • 新建i.py
vi i.py
  • "+P
    • 粘贴代码
name = input()
print(name)
  • :w|!python3 %
    • 保存并运行
  • 但是 这个 有点没头没尾
    • 能否 有点提示(prompt) ?

增加提示

  • 这回有了提示
name = input("what is your name:")
print("Hello", name, "!")
print("And Welcome!")
  • :w|!python3 %
    • 保存并运行当前文件
  • 对着输入的名字
    • 打招呼

输入输出

作用

函数名

参数

输入

input

prompt 提示词

输出

print

values 值
sep 分隔符
end 换行符

函数

操作对象

英文名

input

标准输入流

sys.stdin

print

标准输出流

sys.stdout

  • 再让ai给做一个

询问ai

  • 给ai提示符
    • prompt
  • 代码细节 完全看懂
    • 蛇形命名
    • 赋值
    • 输出

apple

vi apple.py
  • 编写apple.py
apple_count = input("Please enter the number of apples: ")
print("There are", apple_count, "apples.")
  • :w|!python3 %
    • 保存并运行
  • 运行成功

总结

  • 这次
    • 写代码完成了 输入和输出
    • 关于vim 又练了一回
  • 对于vim和shell
    • 我们 要好好总结一下
    • 以后 就不会
    • 再提示得 这么详细 了
  • 我们下次再说!
  • 蓝桥->https://www.lanqiao.cn/courses/3584
  • github->https://github.com/overmind1980/oeasy-python-tutorial
  • gitee->https://gitee.com/overmind1980/oeasypython
最近发表
标签列表