Expressions and strings
The lesson, notes, and homework assignment
- Vocab
- Sequencing Practice
- Selection/Iteration Practice
- Homework/Binary Adaptation
- Vocab
- Substring/length practice
- Concatenation practice
- Homework/List Adaptation
value1 = 5
value2 = value1 ? 1 #step 1
value3 = value2 ? 2 #step 2
value4 = value3 ? 6 #step 3
print(value4)
value1 = 5
value2 = value1 / 10 #step 1
value3 = value2 * 2 #step 2
value4 = value3 - 4 #step 3
print(value4)
# value 4 is -3
numlist = "3","4","9","76","891"
for i in numlist:
if int(i) % 3 == 0:
print( str(i) + " is divisible by 3")
else:
continue
def convert(n):
binary = ""
while int(n) > 0:
binary+=str(int(n%2))
n = n / 2
print(binary[::-1]) # how to reverse string
n = int(input('Enter a number 1-255'))
convert(n)
# I input 30 to get the binary 11110
Vocab
fill in the blanks using the video
Index is a number representing a position, like a character's position in a string or a string's position in a list Concatenation is combining two strings Length is how many characters are in a string A substring is part of a string Pseudocode is writing out a program in plain language with keywords that are used to refer to common coding concepts
string = "hellobye"
print(len(string))
print(string[0 : 5])
print(string[5 : 8])
string1 = "noor"
string2 = "grewal"
string3 = string1 + " " + string2 # added a space in between for readability
print(string3)
names = ["jaden","max","dylan","orlando"]
def length(list):
for name in names:
print(name + ": length " + str(len(name)))
length(names)