Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen If/else expressions with multiple conditions (2/2) | Conditional statements
Learn Python from Scratch

book
If/else expressions with multiple conditions (2/2)

Remember the task you completed two chapters ago. There you wrote if/else statement to check whether the number is even or odd. This time let's modify it so now it will detect zeros and negative numbers.

Aufgabe

Swipe to start coding

Modify your code (from the exercise about checking if the number is even or odd) so it will detect zero and print the message "This is null" and negative numbers with message "This number is negative". Think carefully about the order of conditions.

Lösung

#Do not change number
number = -460807 % 19

# modify your if/else statements
if number == 0:
# write your code below
print('This is null')
elif number < 0:
# write your code below
print('This number is negative')
elif number % 2 == 0:
print('Even')
else:
print('Odd')

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 6
# Do not change number
number = -460807 % 19

# modify your if/else statements
if _ _ _:
# write your code below
_ _ _
_ _ _:
# write your code below
_ _ _
elif number % 2 == 0:
print('Even')
else:
print('Odd')
toggle bottom row
some-alt