Pewnie nienajlepsze rozwiązanie, ale działa.
def setPower(pm25, pm10):
if 0 <= pm25 <= 12:
power1 = 0
elif 13 <= pm25 <= 16:
power1 = 1
elif 37 <= pm25 <= 60:
power1 = 2
elif 61 <= pm25 <= 84:
power1 = 3
elif 85 <= pm25 <= 120:
power1 = 4
elif pm25 > 120:
power1 = 5
if 0 <= pm10 <= 20:
power2 = 0
elif 21 <= pm10 <= 60:
power2 = 1
elif 61 <= pm10 <= 100:
power2 = 2
elif 101 <= pm10 <= 140:
power2 = 3
elif 141 <= pm10 <= 200:
power2 = 4
elif pm10 > 200:
power2 = 5
if power1 == power2:
return power1 # lub power2
elif power1 > power2:
return power1
else:
return power2
Odpowiedź
Kod źródłowy w załączniku.
Jeżeli sprawdzisz przy pomocy
print(setPower(0, 0))
print(setPower(0, 200))
print(setPower(0, 201))
print(setPower(60, 60))
w wyniku powinno być
0
4
5
2
Wyjaśnienie
Tak jak napisałam zadziała nie tylko dla liczb całkowitych.
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2025 KUDO.TIPS - All rights reserved.
Verified answer
Pewnie nienajlepsze rozwiązanie, ale działa.
def setPower(pm25, pm10):
if 0 <= pm25 <= 12:
power1 = 0
elif 13 <= pm25 <= 16:
power1 = 1
elif 37 <= pm25 <= 60:
power1 = 2
elif 61 <= pm25 <= 84:
power1 = 3
elif 85 <= pm25 <= 120:
power1 = 4
elif pm25 > 120:
power1 = 5
if 0 <= pm10 <= 20:
power2 = 0
elif 21 <= pm10 <= 60:
power2 = 1
elif 61 <= pm10 <= 100:
power2 = 2
elif 101 <= pm10 <= 140:
power2 = 3
elif 141 <= pm10 <= 200:
power2 = 4
elif pm10 > 200:
power2 = 5
if power1 == power2:
return power1 # lub power2
elif power1 > power2:
return power1
else:
return power2
Odpowiedź
Kod źródłowy w załączniku.
Jeżeli sprawdzisz przy pomocy
print(setPower(0, 0))
print(setPower(0, 200))
print(setPower(0, 201))
print(setPower(60, 60))
w wyniku powinno być
0
4
5
2
Wyjaśnienie
Tak jak napisałam zadziała nie tylko dla liczb całkowitych.