Beginner · Conditions · 66 of 264
Day of the week
Read a number from 1 to 7 and print the day: 1 is Monday, 7 is Sunday. For any other number print Invalid.
Input: a whole number. Output: the day's name, or Invalid
Examples
Input
1
Output
Monday
Input
5
Output
Friday
Input
7
Output
Sunday
2 more tests check other inputs when you press Check.
Stuck? The idea behind conditions
An if statement runs its indented lines only when the condition is true; elif tries another condition; else catches everything left.
Compare with == (equal), != (not equal), <, <=, >, >=, and join conditions with and, or, not.
n = int(input())
if n > 0:
print("positive")
elif n < 0:
print("negative")
else:
print("zero")Watch for: = gives a value, == compares. And the order of elif matters: the first true one wins, so test the narrow case first.