- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在制作一个Python程序来比较两个时间表,但我经常遇到这个问题。变量、文本和其他所有内容的命名将非常重复,例如,每周 5 节课,输入 12345123451234512345。有没有一种简单的方法可以自动执行此操作?
这是我的程序:
m1= input("M1")
m2= input('M2')
m3= input('M3')
m4= input('M4')
m5= input('M5')
t1= input('T1')
t2= input('T2')
t3= input('T3')
t4= input('T4')
t5= input('T5')
w1= input('W1')
w2= input('W2')
w3= input('W3')
w4= input('W4')
w5= input('W5')
th1= input('TH1')
th2= input('TH2')
th3= input('TH3')
th4= input('TH4')
th5= input('TH5')
f1= input('F1')
f2= input('F2')
f3= input('F3')
f4= input('F4')
f5= input('F5')
am1= input('1M1')
am2= input('1M2')
am3= input('1M3')
am4= input('1M4')
am5= input('1M5')
at1= input('1T1')
at2= input('1T2')
at3= input('1T3')
at4= input('1T4')
at5= input('1T5')
aw1= input('1W1')
aw2= input('1W2')
aw3= input('1W3')
aw4= input('1W4')
aw5= input('1W5')
ath1= input('1TH1')
ath2= input('1TH2')
ath3= input('1TH3')
ath4= input('1TH4')
ath5= input('1TH5')
af1= input('1F1')
af2= input('1F2')
af3= input('1F3')
af4= input('1F4')
af5= input('1F5')
pbm1= input("M1")
pbm2= input('M2')
pbm3= input('M3')
pbm4= input('M4')
pbm5= input('M5')
pbt1= input('T1')
pbt2= input('T2')
pbt3= input('T3')
pbt4= input('T4')
pbt5= input('T5')
pbw1= input('W1')
pbw2= input('W2')
pbw3= input('W3')
pbw4= input('W4')
pbw5= input('W5')
pbth1= input('TH1')
pbth2= input('TH2')
pbth3= input('TH3')
pbth4= input('TH4')
pbth5= input('TH5')
pbf1= input('F1')
pbf2= input('F2')
pbf3= input('F3')
pbf4= input('F4')
pbf5= input('F5')
pbam1= input('1M1')
pbam2= input('1M2')
pbam3= input('1M3')
pbam4= input('1M4')
pbam5= input('1M5')
pbat1= input('1T1')
pbat2= input('1T2')
pbat3= input('1T3')
pbat4= input('1T4')
pbat5= input('1T5')
pbaw1= input('1W1')
pbaw2= input('1W2')
pbaw3= input('1W3')
pbaw4= input('1W4')
pbaw5= input('1W5')
pbath1= input('1TH1')
pbath2= input('1TH2')
pbath3= input('1TH3')
pbath4= input('1TH4')
pbath5= input('1TH5')
pbaf1= input('1F1')
pbaf2= input('1F2')
pbaf3= input('1F3')
pbaf4= input('1F4')
pbaf5= input('1F5')
if(m1==pbm1):
print("Same for week 1 Monday Lesson 1")
if(m2==pbm2):
print("Same for week 1 Monday lesson 2")
if(m3==pbm3):
print("Same for week 1 Monday Lesson 3")
if(m4==pbm4):
print("Same for week 1 Monday Lesson 4")
if(m5==pbm5):
print("Same for week 1 Monday Lesson 5")
if(t1==pbt1):
print("Same for week 1 Tuesday Lesson 1")
if(t1==pbt2):
print("Same for week 1 Tuesday Lesson 2")
if(t1==pbt3):
print("Same for week 1 Tuesday Lesson 3")
if(t1==pbt4):
print("Same for week 1 Tuesday Lesson 4")
if(t1==pbt5):
print("Same for week 1 Tuesday Lesson 5")
if(w1==pbw1):
print("Same for week 1 Wednesday Lesson 1")
if(w2==pbw2):
print("Same for week 1 Wednesday Lesson 2")
if(w3==pbw3):
print("Same for week 1 Wednesday Lesson 3")
if(w4==pbw4):
print("Same for week 1 Wednesday Lesson 4")
if(w5==pbw5):
print("Same for week 1 Wednesday Lesson 5")
if(th1==pbth1):
print("Same for week 1 Thursday Lesson 1")
if(th2==pbth2):
print("Same for week 1 Thursday Lesson 2")
if(th3==pbth3):
print("Same for week 1 Thursday Lesson 3")
if(th4==pbth4):
print("Same for week 1 Thursday Lesson 4")
if(th5==pbth5):
print("Same for week 1 Thursday Lesson 5")
if(f1==pbf1):
print("Same for week 1 Friday Lesson 1")
if(f2==pbf2):
print("Same for week 1 Friday Lesson 2")
if(f3==pbf3):
print("Same for week 1 Friday Lesson 3")
if(f4==pbf4):
print("Same for week 1 Friday Lesson 4")
if(f5==pbf5):
print("Same for week 2 Friday Lesson 5")
if(am1==pbam1):
print("Same for week 2 Monday Lesson 1")
if(am2==pbam2):
print("Same for week 2 Monday lesson 2")
if(am3==pbam3):
print("Same for week 2 Monday Lesson 3")
if(am4==pbam4):
print("Same for week 2 Monday Lesson 4")
if(am5==pbam5):
print("Same for week 2 Monday Lesson 5")
if(at1==pbat1):
print("Same for week 2 Tuesday Lesson 1")
if(at1==pbat2):
print("Same for week 2 Tuesday Lesson 2")
if(at1==pbat3):
print("Same for week 2 Tuesday Lesson 3")
if(at1==pbat4):
print("Same for week 2 Tuesday Lesson 4")
if(at1==pbat5):
print("Same for week 2 Tuesday Lesson 5")
if(aw1==pbaw1):
print("Same for week 2 Wednesday Lesson 1")
if(aw2==pbaw2):
print("Same for week 2 Wednesday Lesson 2")
if(aw3==pbaw3):
print("Same for week 2 Wednesday Lesson 3")
if(aw4==pbaw4):
print("Same for week 2 Wednesday Lesson 4")
if(aw5==pbaw5):
print("Same for week 2 Wednesday Lesson 5")
if(ath1==pbath1):
print("Same for week 2 Thursday Lesson 1")
if(ath2==pbath2):
print("Same for week 2 Thursday Lesson 2")
if(ath3==pbath3):
print("Same for week 2 Thursday Lesson 3")
if(ath4==pbath4):
print("Same for week 2 Thursday Lesson 4")
if(ath5==pbath5):
print("Same for week 2 Thursday Lesson 5")
if(af1==pbaf1):
print("Same for week 2 Friday Lesson 1")
if(af2==pbaf2):
print("Same for week 2 Friday Lesson 2")
if(af3==pbaf3):
print("Same for week 2 Friday Lesson 3")
if(af4==pbaf4):
print("Same for week 2 Friday Lesson 4")
if(af5==pbaf5):
print("Same for week 2 Friday Lesson 5")
你现在看到了吗?
第二次尝试失败
m_input = {}
for i in range(1, 6):
m_input['M{}'.format(i)] = input('input M{}: '.format(i))
bm_input = {}
for i in range(1, 6):
m_input['bM{}'.format(i)] = input('input bM{}: '.format(i))
if (m_input['M1']==bm_input['bM1']):
print("Same for week 1 Monday Lesson 1")
if (m_input['M2']==bm_input['bM2']):
print("Same for week 1 Monday Lesson 1")
if (m_input['M3']==bm_input['bM3']):
print("Same for week 1 Monday Lesson 1")
if (m_input['M4']==bm_input['bM1']):
print("Same for week 1 Monday Lesson 1")
if (m_input['M5']==bm_input['bM1']):
print("Same for week 1 Monday Lesson 1")
为什么没有成功?
最佳答案
您可以尝试使用数组代替所有变量和 for 循环来添加数据:
for i in range(5)
myarray.append("m" + str(i+1))
关于python - 输入重复代码(Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24043344/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!