python文件输出(从基础到应用)

本文主要介绍了使用Python进行基础程序开发,包括打开、写入和读取docx文档,以及进阶版本中如何处理用户输入并实现循环控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、基础程序

import os
# import easygui as g
f = open("a.docx", 'w')#docx可换为txt
f.close()
os.remove("a.docx")
# l=g.enterbox("你终于离开了,请写下你的评价",title="猜数字游戏")
time=int(input("你要输入几行?"))
f = open("a.docx", 'w')
l=input()
print("你的输入是:",l)
f.close()
n1=l
f = open("a.docx", 'a')
f.write(n1)
while time-1>0:
    time=time-1
    l=input()
    print("你的输入是:",l)
    f.close()
    n1="\n"+l
    f = open("a.docx", 'a')
    f.write(n1)
f.close()
print("输出成功")

二、进阶

import os
# import easygui as g
f = open("a.docx", 'w')
f.close()
os.remove("a.docx")
# l=g.enterbox("你终于离开了,请写下你的评价",title="猜数字游戏")
# time=int(input("你要输入几行?"))
f = open("a.docx", 'w')
l=input()
print("你的输入是:",l)
f.close()
n1=l
f = open("a.docx", 'a')
f.write(n1)
while l!="end":
#     time=time-1
    l=input()
    print("你的输入是:",l)
    f.close()
    n1="\n"+l
    f = open("a.docx", 'a')
    f.write(n1)
f.close()
print("输出成功")

import os
# import easygui as g
f = open("a.docx", 'w')
f.close()
os.remove("a.docx")
print("输入end结束")
# l=g.enterbox("你终于离开了,请写下你的评价",title="猜数字游戏")
# time=int(input("你要输入几行?"))
f = open("a.docx", 'w')
l=input()
print("你的输入是:",l)
f.close()
n1=l
f = open("a.docx", 'a')
f.write(n1)
while l!="end":
#     time=time-1
    if l!=end:
        l=input()
        print("你的输入是:",l)
        f.close()
        n1="\n"+l
        f = open("a.docx", 'a')
        f.write(n1)
f.close()
print("输出成功")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值