Module 4.2 Steps 8 & 9


#1

Hello! My name is Lulu. I am having trouble understanding steps 8 & 9 of module 4.2.

In step 8, I keep trying different codes and keep getting error messages. How do I convert user_input? How do I nest the second conditional inside the first?

In step 9, after guessing 3 times, I happened upon the correct answer, but I’m not sure why it’s correct. Can someone explain it to me?

Thanks!


#2

Hi Lulu,

To answer your first question, “How to convert user_input”, you have to “cast” the input to an int. Remember, when you accept input it comes in as a string.
user_input = input(“Enter an integer:”)
number = int(user_input)

To answer your second question, you have to indent your “nested” loop with two tabs.

if number % 2 == 0:
  print("EVEN!")
        
  if number > 0:
     print("POSITIVE!")

To answer your third question, the first if statement does 7 % 2 and test whether it is equal to 0. 7 % 2 is equal to 1 because 7 % 2 is 3 with 1 remaining. Because the first if statement is not true, the next if statement doesn’t run.

The code inside if statements only run if their expressions, in this case (num % 2) evaluates to True.

Hope I helped. See you in class Monday!