Create a list called list1 that contains 1, 2, 3, 4, 5
list1 = [1,2,3,4,5]
What is the 2nd index in this list?
list1 = [1, 3, 5, 7, 9]
5
Using a for loop, write a code that counts from 5 to 21
for num in range(5, 22):
___print(num)
Using a for loop, write a code that counts from an int x to 10, counting by 1, using 3 arguments.
x = int(input("Enter the starting number"))
for num in range(x, 11, 1):
___print(num)
Create this shape:
* * * * *
* * * * *
for num1 in range(1, 3):
___for num2 in range(1,6):
______print("*", end=' ')
___print()
Does a list allow duplication of values?
Yes
How do I only print out 7 in this list?
list1 = [1, 3, 5, 7, 9]
print(list1[3])
What will the following code print?
for x in "Hello World":
print(x)
H
e
l
l
o
W
o
r
l
d
Using a for loop, write a code that counts from an int x to an int y, counting by 2
x = int(input("Enter the starting number"))
y = int(input("Enter the ending number"))
for num in range(x, y, 2):
___print(num)
Create a custom rectangle given row and columns.
row = int(input("enter amount of row"))
col = int(input("enter amount of col"))
for num1 in range(1, row+1):
___for num2 in range(1,col+1):
______print("*", end=' ')
___print()
Is a List mutable?
Does order matter in a List?
Yes
Yes
Given a list called list1, change kiwi to eggplant. And print the new list.
list1 = ["apple", "banana", "cherry", "durian", "kiwi"]
list1[4] = "eggplant"
print(list1)
Write a code that print the times table of an int x. (Ex. x=2; output 2,4,6,8,10,12,14,16,18)
for num in range (1, 10):
___print(num * 2)
Using a for loop, write a code that counts from an int x to an int y, counting by z
x = int(input("Enter the starting number"))
y = int(input("Enter the ending number"))
z = int(input("Enter the counting by number"))
for num in range(x, y, z):
___print(num)
Create the whole times table from 1 to 9
for num in range(1,10):
___for num2 in range(1,10):
______print(num * num2, end=' ')
___print()
How to change the list from to include 1,2,3,4,5,6; and how to change the list to 1,2,3,4.
A List is mutable / changeable so that means in order to have change the original tuple you add and remove.
list11.append(6)
list1.insert(5,6)
list11.remove(5)
list1.pop()
Given a list, called list1 = [-24, -6, 0, 46, 36, 25, 66], write a code that prints out the number that are even and zero.
for num in list1:
___if num %2 == 0:
______print(num)
Given a list called list1 that contains 5 whole numbers, print true if it contains 1 and print false if there is not.
for num in list1:
___if num == 1:
______print("true")
___else:
______print("false")
Given a string called string1, replace all the "a" with "z" and print it.
string1 = "a caravan of ants ambled across the arid landscape"
for letter in string1:
___if(letter == "a"):
______letter = "b"
___print(letter, end = '')
Create this shape:
*
* *
* * *
* * * *
for num in range(1, 5):
___for num1 in range(0,num):
______print("*", end=' ')
___print()
Write a program to find the product of the following list:
list1 = [18, 29, 45, 37, 56]
answer = 48671280
list1 = [18, 29, 45, 37, 56]
product = 1
for num in list1:
product = num * product
print(product)
Given a list [-24, -6, 0, 46, 36, 25, 66], write a code that prints out the number that are divisible by 6.
for num in list1:
___if num %6 == 0:
______print(num)
Write a program that starts from zero, counting by 2 and stops at 100. But if the code ever reaches the number 46 print out “Error” and stop the code. Using For loop.
for num in range(0, 101, 2):
___if(num == 46):
______print("error")
______break
___print(num)
Given a string called string1, remove all the "a" and print it.
string1 = "a caravan of ants ambled across the arid landscape"
(Use continue and print)
for letter in string1:
___if(letter == "a"):
______continue
___print(letter, end = '')
Create a custom triangle given the row.
row = int(input("enter amount of row"))
for num in range(1, row+1):
___for num1 in range(0,num):
______print("*", end=' ')
___print()