My If statements are being ignored - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: My If statements are being ignored (/thread-26205.html) |
My If statements are being ignored - Macer_68 - Apr-24-2020 Okay, so basically I'm trying to make a planet generator that will spit out a few numbers based on a few specifications. the problem here is that I have an if statement asking if my temperature is above or below a certain point, and if this is true, only place a certain amount of land flora. I thought this would work fine but I am still getting outputs that shouldn't be possible when the temperature is that low. I don't know if it the "&" or what but it shouldn't be able to print out more than 30% land flora coverage if the temp is below-20 or above 40. can someone help? from random import randint Temp = randint(-80,80) print(Temp) Land = randint(0,100) print("Land:", Land,"%") Water=100-Land print("Water:", Water,"%") if Land >0 & Temp <39 & Temp > -19: LandFlora1 = randint(60,100) print("Land flora coverage:", LandFlora1,"%") LandLife = True elif Land >0 & Temp >=40 or Land >0 & Temp <= -20: LandFlora2 = randint(0,30) print("Land flora coverage:", LandFlora2,"%") LandLife = True else: print("Land life not possible") LandLife = False RE: My If statements are being ignored - michael1789 - Apr-24-2020 You'll need to use "and" instead of "&". RE: My If statements are being ignored - Macer_68 - Apr-24-2020 (Apr-24-2020, 03:48 AM)michael1789 Wrote: You'll need to use "and" instead of "&". Thanks, I feel... really stupid |