Hello everyone.
I wrote this program with conditions but whenever I try to run it, it is printing out the same output for the conditions. What could be problem and how best can it be written?
population = 6001
int(input("Any figure between 0 and 6000: "))
if population >= 0 and population <= 6000:
print("Start taking measures!!")
elif population > 0 <= 3000:
print("Population is normal")
elif population >= 3001 <= 6000:
print("Start taking measures")
else:
print("Over populated")
I moved your question to its own topic because you were asking a question related to your own code for a challenge and were not answering the OP of the other thread. It is always best to create your own thread for you specific question(s).
Iāve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the āpreformatted textā tool in the editor (</>) to add backticks around text.
I am really not that experienced with Python, but in my mind it looks like a strange way to define what population intervals should be used. For example, how can you ever get the message in your first if-statement when the user only can give one input? (the user should never be able to give for example both 0 and 6000 at the same time, if you only accept one value, right?). I fiddled around with it based on similar reasoning with the intervals and wonder if this code performs the operations you intend (perhaps with a bit longer code):
population = int(input("Any figure between 0 and 6000: "))
if population == 0 or population == 6000:
print("Start taking measures!!")
elif population> 0 and population<=3000:
print("Population is normal")
elif population>= 3001 and population<6000:
print("Start taking measures")
elif population > 6000:
print("Over populated")
hello i think your (variableļ¼population) is bigger than 6000. So your your program will only execute ļ¼elseļ¼ļ¼.Besides, your input is not assign to a variable. So your population is static. populationās value always 6001.you need code like this .
population = int(input("Any figure between 0 and 6000: "))
if 6000 >= population >= 0:
print("Start taking measures!!")
elif population > 0 <= 3000:
print("Population is normal")
elif population >= 3001 <= 6000:
print("Start taking measures")
else:
print("Over populated")