Tuesday, July 16, 2019

For if elif else break modulus --- all in one

Script

#!/usr/local/bin/python3.6

magicnumber = 44

for n in range(100):
  if n is magicnumber:
  print(n, " is the magic number")
                break
        elif n % 4 == 0:
  print(n, " is a MULTIPLE of 4")
        else:
                print(n, " is NOT a multiple of 4")

Execution

0  is a MULTIPLE of 4
1  is NOT a multiple of 4
2  is NOT a multiple of 4
3  is NOT a multiple of 4
4  is a MULTIPLE of 4
5  is NOT a multiple of 4
6  is NOT a multiple of 4
7  is NOT a multiple of 4
8  is a MULTIPLE of 4
9  is NOT a multiple of 4
10  is NOT a multiple of 4
11  is NOT a multiple of 4
12  is a MULTIPLE of 4
13  is NOT a multiple of 4
14  is NOT a multiple of 4
15  is NOT a multiple of 4
16  is a MULTIPLE of 4
17  is NOT a multiple of 4
18  is NOT a multiple of 4
19  is NOT a multiple of 4
20  is a MULTIPLE of 4
21  is NOT a multiple of 4
22  is NOT a multiple of 4
23  is NOT a multiple of 4
24  is a MULTIPLE of 4
25  is NOT a multiple of 4
26  is NOT a multiple of 4
27  is NOT a multiple of 4
28  is a MULTIPLE of 4
29  is NOT a multiple of 4
30  is NOT a multiple of 4
31  is NOT a multiple of 4
32  is a MULTIPLE of 4
33  is NOT a multiple of 4
34  is NOT a multiple of 4
35  is NOT a multiple of 4
36  is a MULTIPLE of 4
37  is NOT a multiple of 4
38  is NOT a multiple of 4
39  is NOT a multiple of 4
40  is a MULTIPLE of 4
41  is NOT a multiple of 4
42  is NOT a multiple of 4
43  is NOT a multiple of 4
44  is the magic number



No comments:

Post a Comment