# In class-examples, February 3, 2020

In [2]:
apikey="SECRET!!"

In [5]:
for x in range(1,101):
if x %3==0 and x %5==0:
print("fizzbuzz")
elif x %3==0:
print("fizz")
elif x %5==0:
print("buzz")
else:
print(int(x))

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
fizz
22
23
fizz
buzz
26
fizz
28
29
fizzbuzz
31
32
fizz
34
buzz
fizz
37
38
fizz
buzz
41
fizz
43
44
fizzbuzz
46
47
fizz
49
buzz
fizz
52
53
fizz
buzz
56
fizz
58
59
fizzbuzz
61
62
fizz
64
buzz
fizz
67
68
fizz
buzz
71
fizz
73
74
fizzbuzz
76
77
fizz
79
buzz
fizz
82
83
fizz
buzz
86
fizz
88
89
fizzbuzz
91
92
fizz
94
buzz
fizz
97
98
fizz
buzz

In [7]:
for x in range(1, 101):
outstring = ""
if x % 3 == 0:
outstring += "fizz"
if x % 5 == 0:
outstring += "buzz"
if outstring:
print(outstring)
else:
print(x)

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
fizz
22
23
fizz
buzz
26
fizz
28
29
fizzbuzz
31
32
fizz
34
buzz
fizz
37
38
fizz
buzz
41
fizz
43
44
fizzbuzz
46
47
fizz
49
buzz
fizz
52
53
fizz
buzz
56
fizz
58
59
fizzbuzz
61
62
fizz
64
buzz
fizz
67
68
fizz
buzz
71
fizz
73
74
fizzbuzz
76
77
fizz
79
buzz
fizz
82
83
fizz
buzz
86
fizz
88
89
fizzbuzz
91
92
fizz
94
buzz
fizz
97
98
fizz
buzz

In [8]:
for x in range (1, 101):
if x%3==0:
print('fizz')
elif x%5==0:
print('buzz')
elif (x%3==0 & x%5==0):
print('fizzbuzz')
else:
print (x)

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizz
16
17
fizz
19
buzz
fizz
22
23
fizz
buzz
26
fizz
28
29
fizz
31
32
fizz
34
buzz
fizz
37
38
fizz
buzz
41
fizz
43
44
fizz
46
47
fizz
49
buzz
fizz
52
53
fizz
buzz
56
fizz
58
59
fizz
61
62
fizz
64
buzz
fizz
67
68
fizz
buzz
71
fizz
73
74
fizz
76
77
fizz
79
buzz
fizz
82
83
fizz
buzz
86
fizz
88
89
fizz
91
92
fizz
94
buzz
fizz
97
98
fizz
buzz

In [9]:
if x == cat:
do_something()
else if x == dog:
do_something_else()
else if x == bear:
do_a_third_thing()

  File "<ipython-input-9-ca1c8705ab3b>", line 3
else if x == dog:
^
SyntaxError: invalid syntax

In [12]:
for x in range(1,101):
if x %3==0 and x %5==0:
print("fizzbuzz")
elif x %3==0:
print("fizz")
elif x %5==0:
print("buzz")

fizz
buzz
fizz
fizz
buzz
fizz
fizzbuzz
fizz
buzz
fizz
fizz
buzz
fizz
fizzbuzz
fizz
buzz
fizz
fizz
buzz
fizz
fizzbuzz
fizz
buzz
fizz
fizz
buzz
fizz
fizzbuzz
fizz
buzz
fizz
fizz
buzz
fizz
fizzbuzz
fizz
buzz
fizz
fizz
buzz
fizz
fizzbuzz
fizz
buzz
fizz
fizz
buzz

In [13]:
for x in range(1, 101):
outstring = ""
if x % 3 == 0:
outstring += "fizz"
if x % 5 == 0:
outstring += "buzz"
if outstring:
print(outstring)
if not outstring:
print(x)

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
fizz
22
23
fizz
buzz
26
fizz
28
29
fizzbuzz
31
32
fizz
34
buzz
fizz
37
38
fizz
buzz
41
fizz
43
44
fizzbuzz
46
47
fizz
49
buzz
fizz
52
53
fizz
buzz
56
fizz
58
59
fizzbuzz
61
62
fizz
64
buzz
fizz
67
68
fizz
buzz
71
fizz
73
74
fizzbuzz
76
77
fizz
79
buzz
fizz
82
83
fizz
buzz
86
fizz
88
89
fizzbuzz
91
92
fizz
94
buzz
fizz
97
98
fizz
buzz

In [15]:
def fizzbuzz(start,end):
for x in range (start,end + 1):
if x % 3 == 0 and x % 5 == 0:
print("fizzbuzz")
elif x % 3 == 0:
print("fizz")
elif x % 5 ==0:
print("buzz")
else:
print(x)
fizzbuzz(1,16)

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16

In [16]:
fizzbuzz(-20, 20)

buzz
-19
fizz
-17
-16
fizzbuzz
-14
-13
fizz
-11
buzz
fizz
-8
-7
fizz
buzz
-4
fizz
-2
-1
fizzbuzz
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz

In [17]:
print(fizzbuzz(1,16))

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
None

In [18]:
x = fizzbuzz(1, 16)

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16

In [19]:
print(x)

None

In [21]:
def fizzbuzz_test(x):
if x % 3 == 0 and x % 5 == 0:
return "fizzbuzz"
elif x % 3 == 0:
return "fizz"
elif x % 5 ==0:
return "buzz"
else:
return x

In [22]:
def fizzbuzz2(start, stop):
for x in range(start, stop + 1):
print(fizzbuzz_test(x))

In [23]:
fizzbuzz2(1, 16)

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16

In [26]:
def fizzbuzz3(start, stop):
outstring = ""
for x in range(start, stop+1):
outstring += str(fizzbuzz_test(x)) + "\n"
return outstring

In [27]:
print(fizzbuzz3(1, 16))

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16


In [28]:
import datetime

In [29]:
print(datetime.datetime.now())

2020-02-03 21:06:31.860294

In [30]:
import mylib

In [31]:
print(mylib.dog)

worst

In [32]:
print(mylib.cat)

best

In [33]:
from mylib import cat

In [34]:
print(cat)

best

In [36]:
from datetime import datetime

In [37]:
datetime.now()

Out[37]:
datetime.datetime(2020, 2, 3, 21, 17, 6, 960176)
In [38]:
from mylib import *

In [39]:
print(dog)

worst


# https://openstates.org/api/register/¶

In [ ]: