Commit 528894e6 by BellCodeEditor

save project

parent 4c464139
Showing with 21 additions and 34 deletions
def new_input():
total=[]
while True:
unit = input('伞兵,你要吃什么(q退出)')
if unit == 'q':
break
else:
try:
unit = int(unit)
except:
print('请重新输入,')
else:
total.append(unit)
finally:
print('============================')
return total
def sum(money):
count = 0
for i in money:
count = count + i
return count
price = new_input()
pay = sum(price)
print('您一共消费了' + str(pay) + '元.扫码还是现金?' )
\ No newline at end of file
filel=open(r'D:\LYQ/testf.txt','w',encoding='utf-8')
filel.write('小李:10本\n')
filel.write('晓丽:12本\n')
filel.write('小丽:8本\n')
filel.write('小利:7本\n')
filel.close()
\ No newline at end of file
try:
age = int(input('你今年几岁'))
except:
print('要输入整数啊')
else:
if age<18:
print('不可以喝酒噢')
print('程序结束~')
\ No newline at end of file
new_data=''
with open(r'D:\LYQ/testf.txt','r',encoding='utf-8') as filel:
for data in filel:
if '小李:10本' in data:
print('小李数据在文件中')
data=data.replace('小李:10本','小李:11本')
new_data += data
with open(r'D:\LYQ/testf.txt','w',encoding='utf-8') as filel:
filel.write(new_data)
with open(r'D:\LYQ/testf.txt','r',encoding='utf-8') as filel:
a=filel.read()
print(a)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment