Is there a limit to how many logical operators you can have in an if statement in python?
No, but you might want to plan and write your expression to be clear and readable to a human. (This will also make it easier for you to find bugs when something goes wrong.)
How can you make the response so that there is more than one answer.
This sounds like you're looking for if
... elif
syntax, which we'll discuss on Friday!
Is it possible to create a condition that is true as long as one word or character is in the input?
Yes, we'll do this on Friday!
Can python be used to affect the terminal? e.g. Can you use it to create a new directory?
Yes, Python can be used to create a new directory, move files around, and do lots of other things on the computer. We probably won't get to these uses this semester, though.
How we can account for the fact that people don't always respond exactly the way we want them to?
We'll see some ways of handling this using while
loops next week.
Just to clarify, does the "not" operator just switch the answer to True if it was False and vice versa?
Yes, that's exactly what it does!
What is the point of using the not logical operator?
The point is to switch Boolean values. One reason you might do this is for tests that are easier to write in a negation than in a positive way --- for example, if we're looking for strings that don't contain the lowercase letter q, we could write something like:
if not ('q' in word):
print("That word doesn't contain a q!")
... and this is easier to write, and to read.
Can you have multiple if statements under one if statement? Like if one thing is true, then you test if another thing is true? / can you nest conditional statements inside of each other?
Yes, absolutely! If you look at the file jacket.py
in your cs21/inclass/03
directory, you'll see some nested if statements. (They are called "nested" when one if statement appears inside the body --- that is, indented --- of another if statement.)
are there cases where multiple else statements are used?
No, each if
statement can have at most one else
. (It can have one or zero else
statements, but not more than one.)