编程语言
首页 > 编程语言> > 卷上卷队——钟某人python刷题的day17——100道python例题

卷上卷队——钟某人python刷题的day17——100道python例题

作者:互联网

今天的第一题~

有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中。

没有难度,直接上代码

dict1 = ['a','b','c','e']
dict2 = ['w','r','f','g']
new_list = dict1+dict2
new_list.sort()
print(new_list)

第二题~

从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件"test"中保存。

用个upper函数就可以转换为大写字母了,看代码

in_ = input('请输入小写字母:').upper()
with open('test.txt','a') as f:
    f.write(in_)

第三题~

从键盘输入一些字符,逐个把它们写到磁盘文件上,直到输入一个 # 为止。

没有难度,直接上代码:

in_ = input('请')
while in_ != '#':
    with open('test.txt','a') as f:
        f.write(in_)
    in_ = input('请')

标签:文件,python,list,day17,input,test,new,磁盘,例题
来源: https://blog.csdn.net/m0_56625413/article/details/122411372