Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson12-4
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
872cd2c6
authored
Sep 12, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
a8d02629
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
0 deletions
diy.py
interesting.py
wew.py
diy.py
0 → 100644
View file @
872cd2c6
# 写入同学们的捐赠明细:'小兰: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
interesting.py
0 → 100644
View file @
872cd2c6
# 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
+
'='
+
'
%.3
f'
%
(
float
(
op1
)
+
float
(
op2
)))
elif
(
op
==
'-'
):
#print(op1 + '-' + op2 + '=' + str(float(op1) - float(op2)))
print
(
op1
+
'-'
+
op2
+
'='
+
'
%.3
f'
%
(
float
(
op1
)
-
float
(
op2
)))
elif
(
op
==
'*'
):
#print(op1 + '*' + op2 + '=' + str(float(op1) * float(op2)))
print
(
op1
+
'*'
+
op2
+
'='
+
'
%.3
f'
%
(
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
+
'='
+
'
%.3
f'
%
(
float
(
op1
)
/
float
(
op2
)))
elif
(
op
==
'^'
):
#print(op1 + '^' + op2 + '=' + str(float(op1) ** float(op2)))
print
(
op1
+
'^'
+
op2
+
'='
+
'
%.3
f'
%
(
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
wew.py
0 → 100644
View file @
872cd2c6
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment