We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
We're comparing user input to a set of conditions we've set out in our program. If the input matches the conditions, the program will print a message. A basic example of an if statement would be:
if(1>=0):return"Spam"
With regard to the question however, we're given multiple conditions and our program has to respond to those conditions as such. There are three outputs that expect a "Weird" output so we'll do a single if statement to address that
if(ninrange(6,21)orn%2!=0):return"Weird"
Firstly, we are saying if n is between the range of 6 and 21 (21 is not counted) print "Weird", we're also saying that if n is not an even number -- print the same result.
Lastly, we can just use an else statement to print off any remaining statements if none of test cases matched the previous conditions.
Python If-Else
You are viewing a single comment's thread. Return to all comments →
To summarise:
We're comparing user input to a set of conditions we've set out in our program. If the input matches the conditions, the program will print a message. A basic example of an if statement would be:
With regard to the question however, we're given multiple conditions and our program has to respond to those conditions as such. There are three outputs that expect a "Weird" output so we'll do a single if statement to address that
Firstly, we are saying if n is between the range of 6 and 21 (21 is not counted) print "Weird", we're also saying that if n is not an even number -- print the same result.
Lastly, we can just use an else statement to print off any remaining statements if none of test cases matched the previous conditions.
And that's it, really. Best of luck!