'How to add a rating to a value in python
19/3/22
I am trying to add a rating of severity to an air_quality index.
Ive tried:
def determine_score(aqi):
if aqi >= 0 and aqi <= 50:
return "Normal"
elif aqi >= 51 and aqi <= 100:
return "Mild"
elif aqi >= 101 and aqi <= 150:
return "Moderate"
elif aqi >= 151 and aqi <= 250:
return "Some Unhealthy"
else:
return " All unhealthy"
lbl2.config("<return>", determine_score)
Solution 1:[1]
So, the function of lbl2 is unclear. But the calling of the function is not proper. the function requires an argument. So call it using
determine_score(aqi) # aqi is the value of the aqi you want to check
Since the commands kinda seem like tkinter, if they are you need to use lambda functions. Though I am not very familiar with tkinter.
lbl2.config("", lambda: determine_score(input_from_user))
Reference: https://www.tutorialspoint.com/tkinter-button-commands-with-lambda-in-python
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anshumaan Mishra |
