Calvin (Deutschbein)
W4Wed: 18 Sep
>>> x = "hello world"
>>> print(x)
hello world
>>> type(x)
<class 'str'>
>>> for student in cs_majors:
... if 'Sophomore' in student:
... x += 1
>>> 1234 * 5678
7006652
>>> 9.9 ** 20 + 1000 == 9.9 ** 20
True
>>> letters = 0
>>> for letter in book:
... letters += 1
...
>>> letters
1496244
>>> es = 0
>>> for letter in book:
... if 'e' == letter:
... es += 1
...
>>> es
147006
name = 'calvin'
name = 'calvin'
name = "L'Ouverture"
name = 'calvin'
name = "L'Ouverture"
book = """It is a truth universally acknowledged, that a single man in possession of a good fortune must be in want of a wife.
However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the mind"""
name = 'calvin'
name = "L'Ouverture"
book = """It is a truth universally acknowledged, that a single man in possession of a good fortune must be in want of a wife.
However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the mind"""
number = str(105 * 4)
number = str(105 * 4)
>>> str(10) == 10
False
>>> x = 10
>>> type(x)
<class 'int'>
>>> x = str(x)
>>> type(x)
<class 'str'>
>>> print('CS' + '151') # there won't be spaces...
CS151
>>> print('CS' + 151) # won't work
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str
>>> number = 151
>>> prefix = 'CS'
>>> prefix + str(number)
'CS151'
>>> number = 151
>>> prefix = 'CS'
>>> prefix + ' ' + str(number)
'CS151'
>>> number = 151
>>> prefix = 'CS'
len()
>>> len(range(0,50,7)) # 0, 7, 14, 21... 28, 35, 42, 49
8
len()
>>> letters
1496244
>>> len(book)
1496244
def right_pad(prefix, number):
if len(prefix) == 2: # CS
return prefix + " " + number
if len(prefix) == 3: # IDS
return prefix + " " + number
if len(prefix) == 4: # DATA
return prefix + " " + number
if len(prefix) == 5: # PHEAL
return prefix + number
def n_spaces(n):
s = ""
for i in range(n):
s = s + " "
return s
def right_pad(prefix, number):
if len(prefix) == 2: # CS
return prefix + n_spaces(3) + number
if len(prefix) == 3: # IDS
return prefix + n_spaces(2) + number
if len(prefix) == 4: # DATA
return prefix + n_spaces(1) + number
if len(prefix) == 5: # PHEAL
return prefix + n_spaces(0) + number
def n_spaces(n):
s = ""
for i in range(n):
s = s + " "
return s
def right_pad(prefix, number):
# wait a minute...
num_spaces = 5 - len(prefix) # the longest is 5
return prefix + n_spaces(num_spaces) + number
def n_spaces(n):
return " " * n
def right_pad(prefix, number):
# wait a minute...
num_spaces = 5 - len(prefix) # the longest is 5
return prefix + n_spaces(num_spaces) + number
>> print("hi" * 3) # mfw i see bae
hihihi
|
>>> 1 < 2 # baseline
True
>>> 'a' < 'b'
True
>>> 'a' < 'A'
False
>>> 'a' < '1'
False
>>> 'A' < '1'
False
>>> 'a' < 'aa'
True
>>> 'Oregon' < 'Washington'
True
>>>
|
def divisors(n:int) -> int: # this is useful
count = 0
for x in range(2,n):
if n % x == 0:
print(x)
count = count + 1
return count
def n_spaces_before(n:int,s:str) -> NoneType: # print -> None
print(n * ' ', s) # test - that is 'n times space plus s'