Identifying and Correcting Errors
Display of the code from the identifying and fixing errors lesson
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
- What is a good test case to check the current outcome? Why?
 - Make changes to get the intended outcome.
 
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
- What is a good test case to check the current outcome? Why?
 - Make changes to get the intended outcome.
 
letter = input("What letter would you like to check?")
count = 0
for i in alphabetList:
    
    if i == letter:
        print("The letter " + letter + " is the " + str(count) + " letter in the alphabet")
    count += 1
This code outputs the even numbers from 0 - 10 using a while loop.
- Analyze this code to determine what can be changed to get the outcome to be odd numbers. (Code block below)
 
evens = []
i = 0
while i <= 10:
    evens.append(i)
    i += 2
print(evens)    
This code should output the odd numbers from 0 - 10 using a while loop.
odds = []
i = 1
while i <= 10:
    odds.append(i)
    i += 2
print(odds)
This code outputs the even numbers from 0 - 10 using a for loop.
- Analyze this code to determine what can be changed to get the outcome to be odd numbers. (Code block below)
 
numbers = [0,1,2,3,4,5,6,7,8,9,10]
evens = []
for i in numbers:
    if (numbers[i] % 2 == 0):
        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]
odds = []
for i in numbers:
    if (numbers[i] % 2 != 0):
        odds.append(numbers[i])
print(odds)
The intended outcome is printing a number between 1 and 100 once, if it is a multiple of 2 or 5
- What values are outputted incorrectly. Why?
 - Make changes to get the intended outcome.
 
numbers = []
newNumbers = []
i = 0
while i <= 100:
    numbers.append(i)
    i += 1
for i in range (1, 101):
    if numbers[i] % 5 == 0:
        newNumbers.append(numbers[i])
    elif numbers[i] % 2 == 0:
        newNumbers.append(numbers[i])
print(newNumbers) 
menu =  {"burger": 3.99,
         "fries": 1.99,
         "drink": 0.99}
total = 0
#shows the user the menu and prompts them to select an item
print("Menu")
for k,v in menu.items():
    print(k + "  $" + str(v)) #why does v have "str" in front of it?
#ideally the code should prompt the user multiple times
count = input("How many items do you want?")
i = 0
print("Your order")
while i < int(count):
    item = input("Please select from the menu")
    total = total + menu[item]
    print(item)
    i += 1
    
#code should add the price of the menu items selected by the user 
print("Total is $" + str(total))