alphabet = "abcdefghijklmnopqrstuvwxyz"

alphabetList = []

for i in alphabet:
    alphabetList.append(i)

print(alphabetList)
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

The intended outcome is to determine where the letter is in the alphabet using a while loop

Changes: Change str(i) to str(i+1) since the index of an array starts at 0.

letter = input("What letter would you like to check?")

i = 0 

while i < 26:
    if alphabetList[i] == letter:
        # Changed
        print("The letter " + letter + " is the " + str(i+1) + " letter in the alphabet")
    i += 1
The letter a is the 1 letter in the alphabet

Printing odd numbers

Change i=0 to i=1 to start at the odd number of 1 and not the even number of 0.

odd = []
i = 1

while i <= 10:
    odd.append(i)
    i += 2

print(odd)    
[1, 3, 5, 7, 9]

Change the modulo from 0 to 1 (odd numbers divide by 2 result in a remainder of 1)

numbers = [0,1,2,3,4,5,6,7,8,9,10]
odd = []

for i in numbers:
    if (numbers[i] % 2 == 1):
        odd.append(numbers[i])

print(odd)
[1, 3, 5, 7, 9]

Printing a multiple of 2 and 5

Add a simple elif statement so that if the number is divisible by 5, the program moves out of the if statement and does not repeat even if it is divisible by 2.

numbers = []
newNumbers = []
i = 0

while i < 100:
    numbers.append(i)
    i += 1

for i in numbers:
    if numbers[i] % 5 == 0:
        newNumbers.append(numbers[i])
    elif numbers[i] % 2 == 0:
        newNumbers.append(numbers[i])

print(newNumbers) 
[0, 2, 4, 5, 6, 8, 10, 12, 14, 15, 16, 18, 20, 22, 24, 25, 26, 28, 30, 32, 34, 35, 36, 38, 40, 42, 44, 45, 46, 48, 50, 52, 54, 55, 56, 58, 60, 62, 64, 65, 66, 68, 70, 72, 74, 75, 76, 78, 80, 82, 84, 85, 86, 88, 90, 92, 94, 95, 96, 98]

Challenge

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
print("Please select an item from the menu.")
item = input("Please select an item from the menu")
print(item)

total = menu[item]
print("The price of " + item + " is " + str(total))
    


#code should add the price of the menu items selected by the user 
print("Your total price is: $" + str(total))
Menu
burger  $3.99
fries  $1.99
drink  $0.99
Please select an item from the menu.
burger
The price of burger is 3.99
Your total price is: $3.99
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
print("Please select an item from the menu. Enter 'done' to finish")
item = input("Please select an item from the menu")
print(item)

while item != "done": 
    total += menu[item]
    item = input("Please select an item from the menu")
    print(item)
    
    


#code should add the price of the menu items selected by the user 
print("Your total price is: $" + str(total))
Menu
burger  $3.99
fries  $1.99
drink  $0.99
Please select an item from the menu. Enter 'done' to finish
burger
burger
fries
drink
done
Your total price is: $10.96

Hacks

  • Possible errors could pertain to first finding an API that provides a reverse dictionary, and then connecting it from frontend to backend. Other errors could occur when the reverse dictionary can not find a word based on the user's inputted definition or if the reverse dictionary outputs incorrect words.

  • Test cases could be testing out each individual section of the code, for instance, first testing out one specific word before testing any input. By limiting the testing to one specific thing, we can first focus on the specific before expanding to the general.