Big Idea 1 'Identifying and Correcting Errors'
Practice with identifying and correcting code blocks
alphabet = "abcdefghijklmnopqrstuvwxyz"
alphabetList = []
for i in alphabet:
    alphabetList.append(i)
print(alphabetList)
The intended outcome is to determine where the letter is in the alphabet using a while loop
- There are two changes you can make
 
letter = input("What letter would you like to check?")
i = 0
while i < 26:
    if alphabetList[i] == letter:
        print("The letter " + letter + " is the " + str(i+1) + " letter in the alphabet")
    i += 1
The intended outcome is to determine where the letter is in the alphabet using a for loop
- There are two changes you can make
 
letter = input("What letter would you like to check?") 
   
count = 1
for i in alphabetList:
    if i == letter:
        print("The letter " + letter + " is the " + str(count) + " letter in the alphabet")
    count += 1
This code should output the evens numbers from 0 - 10 using a while loop.
- How can you change the code to only print the odd numbers in the list?
 
evens = []
i = 0
while i <= 10:
    evens.append(numbers[i])
    i += 2
print(evens)    
This code should output the odd numbers from 0 - 10 using a while loop.
evens = []
i = 0
while i <= 10:
    evens.append(numbers[i])
    i += 2
print(evens)
This code should output the evens numbers from 0 - 10 using a for loop.
- How can you change the code to only print the odd numbers in the list?
 
numbers = [0,1,2,3,4,5,6,7,8,9,10]
evens = []
for i in numbers:
    if (numbers[i] % 2 == 1):
        evens.append(numbers[i])
print(evens)
This code should output the odd numbers from 0 - 10 using a for loop.
numbers = [0,1,2,3,4,5,6,7,8,9,10]
evens = []
for i in numbers:
    if (numbers[i] % 2 == 1):
        evens.append(numbers[i])
print(evens)
The intended outcome is printing a number between 1 and 100 once, if it is a multiple of 2 or 5
- 3 changes to the code will give the expected outcome.
 
numbers = []
newNumbers = []
i = 0
while i <= 100:
    numbers.append(i)
    i += 1
for i in numbers:
    if numbers [i] == 0:
        pass
    elif numbers[i] % 5 == 0:
        newNumbers.append(numbers[i])
    elif numbers[i] % 2 == 0:
        newNumbers.append(numbers[i])
print(newNumbers) 
my_Menu =  {"burger": 3.99,
            "fries": 1.99,
            "drink": 0.99}  # define my menu as a dictionary data type, key is the name of food, value is price 
price_total = 0  #set initial value  
for x,y in my_Menu.items():
    print(x,": ","$",y)
print("Please Select an Item")  #prompt user input
myUserInput = "burger"  #define and set initial value
myUserInput = input() #define variable to hold user input
myUserOrderKey = myUserInput  #define and set initial value-- used to print out user's selected key and value
myCounter = 0 #count through the loop 
myError = "Whoops, try again"
for x,y in my_Menu.items(): #loop through my menu
    if x == myUserInput: #if the user input matches a key in my menu dictionary
        print(x,y) #then print the key and value 
        break #stop looping when you get result 
    else:
       myCounter += 1 
       if myCounter == 3:
            print(myError)