Error Testing
alphabet = "abcdefghijklmnopqrstuvwxyz"
alphabetList = []
for i in alphabet:
alphabetList.append(i)
print(alphabetList)
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) + " letter in the alphabet")
i += 1
The letter's value is currently 1 less than what it should be, to fix this, we can add 1 to the str(i)
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
letter = input("What letter would you like to check?")
for i in alphabetList:
count = 0
if i == letter:
print("The letter " + letter + " is the " + str(count) + " letter in the alphabet")
count += 1
All letters are the 0 letter in the alphabet, to fix, we can move count = 0 to outside the loop. But, we have the issue of the value being 1 less than intended so we just change str(count) into str(count+1) again.
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+1) + " letter in the alphabet")
count += 1
evens = []
i = 0
while i <= 10:
evens.append(i)
i += 2
print(evens)
We want to make it print a list of odd numbers rather than even, so changing the start value of i = 0 to i = 1 makes it so adding 2 takes you to the next odd number.
odds = []
i = 1
while i <= 10:
odds.append(i)
i += 2
print(odds)
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)
Similar to the last, we need to change the 0 to a 1 so that adding 2 takes you to the next number
numbers = [0,1,2,3,4,5,6,7,8,9,10]
odds = []
for i in numbers:
if (numbers[i] % 2 == 1):
odds.append(numbers[i])
print(odds)
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])
if numbers[i] % 2 == 0:
newNumbers.append(numbers[i])
print(newNumbers)
We need to make it so that no numbers repeat, since we know factors of 5 and 2 intersect at every 10, we can change "if numbers[i] % 5 == 0:" to "if numbers[i] % 10 == 5:" so that it only prints the 5, 15, 25, 35, etc.
numbers = []
newNumbers = []
i = 0
while i < 101:
numbers.append(i)
i += 1
for i in numbers:
if numbers[i] % 10 == 5:
newNumbers.append(numbers[i])
if 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
item = input("Please select an item from the menu")
#code should add the price of the menu items selected by the user
print(total)
We need to change this code so that we type in our order, and the price adds up to a total.
menu = {"burger": 3.99,
"fries": 2.99,
"drink": 0.99}
total = 0
print("Hello! Please review our menu and type what you would like to order")
print("Menu:")
for k,v in menu.items():
print(k + " $" + str(v)) # shows the name of the item on the menu followed by its price
order = True
while order: # user will be asked for their order multiple times
item = input("choose your order")
if item in menu.keys():
total+= menu[item]
print("you ordered:", item)
print("your total is now:", total)
else: # if the person types something in wrong or finishes their order, it stops
order = False
print("Your Total is:", "$",total)
print("Enjoy your meal")