Commit 872cd2c6 by BellCodeEditor

auto save

parent a8d02629
Showing with 122 additions and 0 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
new_data=''
with file1=open(r'C:\Users\Windows 10\Desktop\111.txt','r',encoding='utf-8')as file1:
for data in file1:
if '小强:10本' in data:
data=data.replace('小强:10本','小强:11本')
new_data+=data
with file1=open(r'C:\Users\Windows 10\Desktop\111.txt','w',encoding='utf-8')as file1:
file1.write(new_data)
\ No newline at end of file
# Skip to content
# Search or jump to…
# Pull requests
# Issues
# Marketplace
# Explore
# @PeterFujiyu
# PeterFujiyu
# /
# python
# Public
# 1
# 00
# Code
# Issues
# Pull requests
# Actions
# Projects
# Wiki
# Security
# Insights
# Settings
# python/yunsuan.py /
# @PeterFujiyu
# PeterFujiyu 增加次方运算
# Latest commit 9ee1d77 28 days ago
# History
# 1 contributor
# 62 lines (48 sloc) 1.91 KB
import sys
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
while True:
op1 = input('请输入第一个运算数(必须是数字):')
if not is_number(op1):
print('抱歉,您第一个运算数输入错误')
sys.exit(1)
op = input('请输入运算符(必须是+,-,*,/,^):')
if not ((op == '+') or (op == '-') or (op == '*') or (op == '/') or (op == '^')):
print('抱歉,您运算符输入错误')
sys.exit(1)
op2 = input('请输入第二个运算数(必须是数字):')
if not is_number(op2):
print('抱歉,您第二个运算数输入错误')
sys.exit(1)
#op1 = float(op1)
#op2 = float(op2)
if (op == '+'):
#print(op1 + '+' + op2 + '=' + str(float(op1) + float(op2)))
print(op1 + '+' + op2 + '=' + '%.3f' % (float(op1) + float(op2)))
elif (op == '-'):
#print(op1 + '-' + op2 + '=' + str(float(op1) - float(op2)))
print(op1 + '-' + op2 + '=' + '%.3f' % (float(op1) - float(op2)))
elif (op == '*'):
#print(op1 + '*' + op2 + '=' + str(float(op1) * float(op2)))
print(op1 + '*' + op2 + '=' + '%.3f' % (float(op1) * float(op2)))
elif (op == '/' ):
if (op2 == 0):
print('抱歉,您输入错误(除数不能为0)')
sys.exit(1)
else:
#print(op1 + '/' + op2 + '=' + str(float(op1) / float(op2)))
print(op1 + '/' + op2 + '=' + '%.3f' % (float(op1) / float(op2)))
elif (op == '^'):
#print(op1 + '^' + op2 + '=' + str(float(op1) ** float(op2)))
print(op1 + '^' + op2 + '=' + '%.3f' % (float(op1) ** float(op2)))
# © 2021 GitHub, Inc.
# Terms
# Privacy
# Security
# Status
# Docs
# Contact GitHub
# Pricing
# API
# Training
# Blog
# About
# Loading complete
\ No newline at end of file
fi = open(r"C:\Users\Windows 10\Desktop\新建文本文档.txt",'w',encoding='utf-8')
#print(fi)
fi.write('小兰:12本')
fi.close()
\ 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