Using python 3.20 Write a for loop that iterates over a list of strings 1st and
ID: 669653 • Letter: U
Question
Using python
3.20 Write a for loop that iterates over a list of strings 1st and prints the first three characters of every word. If 1st is the list ['January' , 'February' , 'March'] then the following should be printed:
Jan
Feb
Mar
3.21 write a loop that iterates over a list of numbers 1st and prints the even numbers in the list. For example, is 1st is [2, 3, 4, 5, 6, 7, 8, 9], then the numbers 2, 4, 6, and 8 should be printed.
3.22 write a for loop that iterates over a list of numbers 1st and prints the even numbers in the list whose square is divisible by 8. For example, of 1st is [2, 3, 4, 5, 6, 7, 8, 9], then the numbers 4 and 8 should be printed.
3.23 write for loops that use the function range () and print the following sequences:
a) 01
b) 0
c) 3 4 5 6
d) 1
e) 0 3
f) 5 9 13 17 21
Explanation / Answer
l=["January","February","March"]
for i in range(0,len(l)):
print(l[i][0:3])
print " "
l1=[2,3,4,5,6,7,8,9]
for i in range(0,len(l1)):
if l1[i]%2==0:
print (l1[i]),
print " "
l1=[2,3,4,5,6,7,8,9]
for i in range(0,len(l1)):
if l1[i]%2==0:
if ((l1[i])*(l1[i]))%8==0:
print (l1[i]),
print " "
for i in range(0,2):
print i,
print " "
for i in range(0,1):
print i,
print " "
for i in range(3,7):
print i,
print " "
for i in range(1,2):
print i,
print " "
for i in range(0,4,3):
print i,
print " "
for i in range(5,22,4):
print i,
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.