mirror of
https://github.com/WMK965/965-Python-Learning-Repo.git
synced 2025-04-27 07:53:21 +00:00
更新 Calculate.py
This commit is contained in:
parent
a6689d7352
commit
4dfd1e6b69
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (PythonLearning)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (PythonLearning)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
@ -4,7 +4,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.10 (PythonLearning)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.11 (PythonLearning)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
19
Calculate.py
19
Calculate.py
@ -4,11 +4,12 @@ In = input()
|
|||||||
'''
|
'''
|
||||||
eval()函数可对括号中的含变量表达式做运算
|
eval()函数可对括号中的含变量表达式做运算
|
||||||
0 1 2 3 4 5 6 :正向递增序号
|
0 1 2 3 4 5 6 :正向递增序号
|
||||||
" 1 2 3 4 5 "
|
a b c d e f g
|
||||||
-7 -6 -5 -4 -3 -2 -1 :反向递减序号
|
-7 -6 -5 -4 -3 -2 -1 :反向递减序号
|
||||||
使用[]获取字符串中一个或多个字符
|
使用[]获取字符串中一个或多个字符
|
||||||
str[0]获取第一个字 str[0:2]获取前两个字 str[0:-1]字符串去掉末位后输出 str[1:]去首位
|
str[0]获取第一个字 str[0:2]获取前两个字 str[0:-1]字符串去掉末位后输出 str[1:]去首位
|
||||||
str[m:n[:k]]m位至n位,k为步长
|
str[m:n[:k]]m位至n位,k为步长
|
||||||
|
str[::-1]倒置字符串
|
||||||
['F', 'f', '℉'] : 列表类型数据
|
['F', 'f', '℉'] : 列表类型数据
|
||||||
'''
|
'''
|
||||||
numdata = eval(In[0:-1])
|
numdata = eval(In[0:-1])
|
||||||
@ -34,3 +35,17 @@ elif In[-1] in ['C', 'c', '°C']:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
print("Syntax Error")
|
print("Syntax Error")
|
||||||
|
'''
|
||||||
|
import math # 引入math库
|
||||||
|
|
||||||
|
a = float(input())
|
||||||
|
b = float(input())
|
||||||
|
c = float(input())
|
||||||
|
delta = math.pow(b, 2) - 4 * a * c# 计算判别式
|
||||||
|
if delta >= 0:
|
||||||
|
x1 = (-b + math.sqrt(delta)) / (2 * a)
|
||||||
|
x2 = (-b - math.sqrt(delta)) / (2 * a) #括号很重要!!!!!!!!!
|
||||||
|
print("X1=", round(x1, 2), " X2=", round(x2, 2))
|
||||||
|
else:
|
||||||
|
print("没有实数解")
|
||||||
|
'''
|
||||||
|
@ -83,7 +83,6 @@ for i in range(0, 5):
|
|||||||
pendown()
|
pendown()
|
||||||
circle(100)
|
circle(100)
|
||||||
'''
|
'''
|
||||||
'''
|
|
||||||
import turtle
|
import turtle
|
||||||
|
|
||||||
|
|
||||||
@ -103,4 +102,3 @@ y = [-75, -75, -75, -155, -155]
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
circle(x[i], y[i], 360, 100, 15, color[i])
|
circle(x[i], y[i], 360, 100, 15, color[i])
|
||||||
turtle.done()
|
turtle.done()
|
||||||
'''
|
|
||||||
|
53
iSmartAnsAnalize/scripts.py
Normal file
53
iSmartAnsAnalize/scripts.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# encoding utf-8
|
||||||
|
import linecache
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def opentxt(num, path, name, line):
|
||||||
|
filename = '.\\{0}\\{1}{2}.txt'.format(path, num, name)
|
||||||
|
cont = linecache.getline(filename, line)
|
||||||
|
return cont
|
||||||
|
|
||||||
|
|
||||||
|
def savetxt(num, path, inv, name, character):
|
||||||
|
filename = '.\\{0}\\{1}{2}.txt'.format(path, num, name)
|
||||||
|
with open(filename, 'w', encoding='UTF-8') as txt:
|
||||||
|
txt.write(inv.replace(character, '\n'))
|
||||||
|
|
||||||
|
|
||||||
|
def txtsearch(num, path, character):
|
||||||
|
filename = '.\\{0}\\{1}_Response.txt'.format(path, num)
|
||||||
|
txt = open(filename, 'r', encoding='UTF-8')
|
||||||
|
lines = txt.readlines()
|
||||||
|
for lines in lines: # 对TXT 进行逐行读取
|
||||||
|
if character in lines:
|
||||||
|
return lines
|
||||||
|
txt.close()
|
||||||
|
|
||||||
|
|
||||||
|
count = 2
|
||||||
|
while count < 26:
|
||||||
|
content = txtsearch(count, 'response', 'answer')
|
||||||
|
texts = re.findall(r'<answers>.*<\\/answers>', content)
|
||||||
|
texts = str(texts)
|
||||||
|
texts = re.findall(r'CDATA\[.]', texts)
|
||||||
|
texts = str(texts)
|
||||||
|
texts = texts.replace("'CDATA[]]'", '\n')
|
||||||
|
texts = texts.replace("CDATA", '')
|
||||||
|
savetxt(count, 'Ans', texts, 'ans', ',')
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
os.chdir(r"C:/Users/965/Builds/iSmartAnsCatch/Ans")
|
||||||
|
filedir = "C:/Users/965/Builds/iSmartAnsCatch/Ans"
|
||||||
|
f = open('../Ans.txt', 'w')
|
||||||
|
# 遍历文件名
|
||||||
|
for i in range(2, 26):
|
||||||
|
filename1 = str(i) + 'ans.txt'
|
||||||
|
if i > 0:
|
||||||
|
filepath = filedir + '/' + filename1
|
||||||
|
# 遍历单个文件 读取行数
|
||||||
|
for line1 in open(filepath, encoding='UTF-8'):
|
||||||
|
f.writelines(str(i - 1) + line1)
|
||||||
|
f.write('\n')
|
||||||
|
f.close()
|
Loading…
Reference in New Issue
Block a user