#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 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"
вместо того, чтобы каждый раз вызывать набор данных каждой весовой категории, можно ли их объединить? Я хочу, чтобы первая и последняя переменная выполнили некоторую математику, но я хочу посмотреть, есть ли лучший способ. Любые идеи будут полезны.