Write a program that compares whether a is greater than b and prints ``True`` or ``False``
%% Cell type:code id:d0f961d8 tags:
``` python
a=10
b=5
a>b
```
%% Output
True
%% Cell type:markdown id:be4e3737 tags:
### 2 Control structures
%% Cell type:markdown id:a0122eba tags:
### 2.1 if and else statements
%% Cell type:markdown id:e9e1fa12 tags:
#### 2.1.1 even number
Write a program that checks a number and outputs whether it is even or odd.
%% Cell type:code id:73e37cc2 tags:
``` python
number=3
ifnumber%2==0:
print("The number is even.")
else:
print("The number is odd.")
```
%% Cell type:code id:273fc6d1 tags:
%% Output
``` python
```
The number is odd.
%% Cell type:markdown id:e2fc0c01 tags:
## 2.1.2 Simple Conditional
Write a program that checks a number from a user input to see whether it is positive, negative or zero.
%% Cell type:code id:811d885d tags:
``` python
number=float(input("Which number?"))
ifnumber>0:
print("Positive")
elifnumber<0:
print("Negative")
else:
print("Zero")
```
%% Output
Positive
%% Cell type:markdown id:eb66c676 tags:
#### 2.1.3 User roles
Write a program that checks the role of a user and issues the corresponding authorizations.<br><br>
**Admin** has all authorizations <br>
**Editor** can edit content <br>
**User** can view content <br>
%% Cell type:code id:4ad521c7 tags:
``` python
role =input("what's your role")
role=input("what's your role?")
ifrole=="admin":
print("Admin has all authorizations.")
elifrole=="editor":
print("Editor can edit content. ")
elifrole=="user":
print("User can view content.")
else:
print("Unknown user cannot access.")
```
%% Cell type:code id:d54646c1 tags:
%% Output
``` python
```
Admin has all authorizations.
%% Cell type:markdown id:d79ce120 tags:
#### 2.1.4 Leap year check
Write a program that checks whether a year is a leap year. A year is a leap year if it is dividable by 4, but not by 100, unless it is also dividable by 400.