+ 1

I’m new and I ran out of hearts

Can someone explain to me how to use “if” and “else” for python or anything else you could teach me or convince me into getting pro

30th Jul 2024, 2:11 AM
Gael
1 Réponse
+ 1
if condition: Do something else: Do something else After the word 'if' there must be a condition. This is a true or false statement. For example, if 1 == 1: This is true, which means any code that is 'inside' this will run. In this case, 'do something' will run, as indicated by the indent, being 'inside' the if statement. The else is what will occur when the condition is false. If I had: 1 == 2: Then the code inside the else statement will run instead. So, you use the if/else statements when you want some code to run conditionally. Only under some specific circumstance.
30th Jul 2024, 2:21 AM
Rrestoring faith
Rrestoring faith - avatar