TroyL99 Posted October 1, 2020 Share Posted October 1, 2020 The following code reason doesn't make sense. If x = 41 and I check if its greater than 10 and 20, why would I print out "but not above 20." x is greater than 20 and it's greater than 30 and 40 as well. Perhaps w3schools could use a better example for beginners to make it more clear. Thank you! Nested If You can have if statements inside if statements, this is called nested if statements. Example x = 41if x > 10: print("Above ten,") if x > 20: print("and also above 20!") else: print("but not above 20.") Link to comment Share on other sites More sharing options...
Funce Posted October 13, 2020 Share Posted October 13, 2020 Hey Troy! Welcome to the Forums! This example is supposed to work for most values of x. Given that x is 41, the only output would be Above ten, and also above 20! And if you changed x to be... for instance 16, the output would be Above ten, but not above 20. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now