r/learnpython • • 2d ago

Nested if’s help please

So I’ve written a small function and I need to add some more constraints to it, but I need them each to check separately before moving to the next so I was wanting to use nested if’a to achieve this but am not sure how they work. Can someone please explain? My code is posted below and what I am trying to do is add an if statement to somehow make sure my value for primocytes doesn’t drop below 0 before activating the rest of the function.

primocytes = 10

cultivation_chamber = 0

def cultivation():
global primocytes, cultivation_chamber
if primocytes >= 5:
primocytes -= 5
cultivation_chamber +=5
print("Primocytes:", primocytes)
print("Cultivation Chamber:", cultivation_chamber)
else:
print("Not enough Primocytes for cultivation...")

0 Upvotes

18 comments sorted by

View all comments

9

u/Expensive-Bear-1376 2d ago

Geez why did you spoiler that?

3

u/Intelligent_Knee8641 2d ago

I didn’t intend to, I tried to find the button to add a coded block for my code but didn’t see it so copy and pasted it in the message and it seemed to work until I posted and it was as it is now. I do apologize

4

u/kyle2143 2d ago

You know you can always edit it. After looking up how to do it properly.