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) + " 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?")
i = 0
while i < 26:
if alphabetList[i] == letter:
print("The letter " + letter + " is the " + str(i + 1) + " letter in the alphabet")
i += 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 == 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]
evens = []
for i in numbers:
if (numbers[i] % 2 == 0):
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 = [1]
newNumbers = [100]
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)