Calvin (Deutschbein)
W4Wed: 17 Sep
x = "hello world"
print(x)
hello world
print(type(x))
<class 'str'>
for student in cs_majors:
if 'Sophomore' in student:
x += 1
print(1234 * 5678)
7006652
print(9.9 ** 20 + 1000 == 9.9 ** 20)
True
>>> letters = 0
for letter in book:
letters += 1
print(letters)
1496244
es = 0
for letter in book:
if 'e' == letter:
es += 1
print(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)
print(str(10) == 10)
False
x = 10
print(type(x))
x = str(x)
print(type(x))
<class 'int'>
<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'
print(prefix + str(number))
CS151
print(prefix + ' ' + str(number))
CS 151
number = 151
prefix = 'CS'
len()
count = len(range(0,50,7)) # 0, 7, 14, 21... 28, 35, 42, 49
print(count)
8
len()
print(letters)
print(len(book))
1496244
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
>>> a = 'something'
>>> b = 'another thing'
>>> a < b
False
print(1 < 2)
print('a' < 'b')
print('a' < 'A')
print('a' < '1')
print('A' < '1')
print('a' < 'aa')
print('Oregon' < 'Washington')
|
True
True
False
False
False
True
True
|
def divisors(n):
count = 0
for x in range(2,n):
if n % x == 0:
print(x)
count = count + 1
return count
def n_spaces_before(n): # print -> None
print(n * ' ', s) # test - that is 'n times space plus s'