Python 3.x 在矩阵中放入一个范围并使用python取出一个特定的数字
我是python新手,我想知道我是否可以在矩阵或数组中设置包含范围的多个变量,而不列出中间的所有数字。目前我的代码看起来像这样Python 3.x 在矩阵中放入一个范围并使用python取出一个特定的数字,python-3.x,Python 3.x,我是python新手,我想知道我是否可以在矩阵或数组中设置包含范围的多个变量,而不列出中间的所有数字。目前我的代码看起来像这样 underweight = range(1,20) normal = range(20,26) prettyfatty = range(26,31) relyfatty = range(31,40) ...... ...... class funke: def diff(*args): if BMI.vari(kiya,kiki) in unde
underweight = range(1,20)
normal = range(20,26)
prettyfatty = range(26,31)
relyfatty = range(31,40)
......
......
class funke:
def diff(*args):
if BMI.vari(kiya,kiki) in underweight:
try:
ok = underweight[0]
top1 = ok - BMI.vari(kiya,kiki)
tweight1 = (top1/703)*height**2
print("You will need to gain" + " " + tweight1 + "pounds to go up a tier. You shouldnt try to lose more weight")
else:
pass
elif BMI.vari(kiya,kiki) in normal:
try:
ok = normal[-1]
ko = normal[0]
top2 = ok - BMI.vari(kiya,kiki)
bottom2 = BMI.vari(kiya,kiki) - ko
tweight2 = (top2/703)*height**2
bweight2 = (bottom2/703)*height**2
print("You will need to gain" + " " + tweight2 + "pounds to go up a tier and lose " + bweight1 " to go down a tier")
else:
pass
elif BMI.vari(kiya,kiki) in prettyfatty:
try:
ok = prettyfatty[-1]
ko = prettyfatty[0]
top3 = ok - BMI.vari(kiya,kiki)
bottom3 = BMI.vari(kiya,kiki) - ko
tweight3 = (top3/703)*height**2
bweight3 = (bottom3/703)*height**2
print("You will need to gain" + " " + tweight3 + "pounds to go up a tier and lose " + bweight1 " to go down a tier")
else:
pass
elif BMI.vari(kiya,kiki) in relyfatty:
try:
ok = relyfatty[-1]
ko = relyfatty[0]
top4 = ok - BMI.vari(kiya,kiki)
bottom4 = BMI.vari(kiya,kiki) - ko
tweight4 = (top4/703)*height**2
bweight4 = (bottom4/703)*height**2
print("You will need to gain" + " " + tweight4 + "pounds to go up a tier and lose " + bweight1 " to go down a tier")
else:
pass
else BMI.vari(kiya,kiki) > relyfatty[-1]:
try:
ok = relyfatty[0]
top5 = BMI.vari(kiya,kiki) - ok
tweight5 = (top1/703)*height**2
print("You will need to lose" + " " + tweight5 + "pounds to go down a tier and you really should")
else:
print("Something went wrong"
不是每次调用每个权重类数据集,而是可以将它们组合起来吗?我想得到第一个和最后一个变量来做一些数学计算,但我想看看是否有更好的方法。任何想法都会有帮助