马士兵Python学习笔记_P146_145.实操案例一

一、实操案例一

在这里插入图片描述

二、代码示例-向文件输出“奋斗成就更好的你”

# 1、向文件输出“奋斗成就更好的你”
# 方式一:使用print方式进行输出(输出的目的地是文件)
fp = open("P146_145_test1.txt", "w", encoding="utf-8")
print("奋斗成就更好的你", file=fp)
fp.close()

# 方式二:使用文件读写操作
with open("P146_145_test2.txt", "w", encoding="utf-8") as wfile:
    wfile.write("奋斗成就更好的你")

运行结果

D:\Environment\Python\Python311\python.exe D:\Environment\PythonWorks\learnpython\马士兵Python\第17章_实操案例\P146_145.实操案例一.py 

Process finished with exit code 0

在这里插入图片描述
在这里插入图片描述

三、代码示例-输出北京天气预报

# 2、输出北京天气预报
print("星期日", "今天")      # 个数可变的位置参数
print("----------------------------------")
print("08时", "11时", "14时", "17时", "20时", "23时")
print("0℃ ", "6℃ ", "10℃ ", "4℃ ", "1℃ ", "0℃")
print("----------------------------------")
print("明天    ", "2/23  ", "2℃/11℃")
print("星期二  ", "2/24  ", "0℃/9℃")
print("星期三  ", "2/25  ", "-2℃/8℃")
print("星期四  ", "2/26  ", "-3℃/6℃")
print("星期五  ", "2/27  ", "-2℃/7℃")
print("星期六  ", "2/28  ", "-1℃/11℃")

运行结果

D:\Environment\Python\Python311\python.exe D:\Environment\PythonWorks\learnpython\马士兵Python\第17章_实操案例\P146_145.实操案例一.py 
星期日 今天
----------------------------------
0811141720230610410----------------------------------
明天     2/23   2/11℃
星期二   2/24   0/9℃
星期三   2/25   -2/8℃
星期四   2/26   -3/6℃
星期五   2/27   -2/7℃
星期六   2/28   -1/11℃

Process finished with exit code 0

B站视频链接:https://www.bilibili.com/video/BV1wD4y1o7AS?p=146

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值