In: Computer Science
Intro to Python!
1. Using while loops, write a program that prints multiples of 5 which are less than 100. Your loop initially starts from 0.
2. Consider B to be a list of alphabetically ordered strings. Using while loops, write a program that only prints words which start with letter A.
B = [Alex, Airplane, Alpha, Australia, Ben, Book, Bank, Circuit, Count, Dark]
3. Using while loop, create a program that only prints first 18 multiples of 7.Hint: Your loop initially starts from 1. You should create a counter to keep track!
Solution
1)
code
i = 0
while i < 100:
if i%5==0 and i!=0:
print(i)
i=i+1
Screenshot
Output
---
2)
Solution
Code
B = ['Alex', 'Airplane', 'Alpha', 'Australia', 'Ben', 'Book',
'Bank', 'Circuit', 'Count', 'Dark']
length = len(B)
i = 0
# Iterating using while loop
while i < length:
if B[i].startswith('A'):
print(B[i])
i += 1
Screenshot
Output
---
3)
Code
i = 1
while i <=18:
print(i*7)
i=i+1
Screenshot
Output
---
all the best