You are on page 1of 1

Exercise‌‌3:‌‌Turn‌‌all‌‌the‌‌values‌‌in‌‌a‌‌list‌‌to‌‌

 
their‌‌square‌‌value‌  ‌
Solution‌‌1:‌  ‌
aList‌=‌‌[
‌‌1,
‌‌‌ 2‌
,‌‌
3,‌‌‌
4‌,‌5
‌,‌‌‌
6‌,‌‌
7]
‌‌‌
 
List‌=
‌‌[‌i**‌ 2‌‌for‌
‌i‌‌‌in‌
‌a‌List]‌‌
 
print(List)‌‌  
 ‌
Solution‌‌2:‌  ‌
aList‌=‌‌[‌‌
1,‌‌‌2‌
,‌‌
3,‌‌‌
4‌,‌5‌,‌‌‌
6‌,‌‌
7]
‌‌‌
 
List‌=‌‌[
‌]‌‌#‌E ‌mpty‌L‌ist‌‌ 
for‌
‌i
‌‌‌in‌
‌a‌List:‌‌ 
L
‌ist.append(i**‌ 2)
‌‌‌
 
print(List)‌‌  
   ‌
Solution‌‌3:‌  ‌
aList‌=‌‌i‌nput()‌‌
 
aList‌=‌‌l‌ist(aList.split())‌‌  
List‌=‌‌[
‌]‌‌#‌E‌mpty‌L‌ist‌‌
 
for‌
‌i
‌‌‌in‌
‌r‌ange(‌0,‌len(aList)):‌‌
 
a
‌List[i]=int(aList[i])‌‌  
for‌
‌i
‌‌‌in‌
‌a‌List:‌‌
 
L
‌ist.append(i**‌ 2)
‌‌‌
 
print(List)‌‌ 
   ‌
 ‌
Exercise‌‌4:‌‌Concatenate‌‌all‌‌the‌‌elements‌‌in‌‌
 
two‌‌lists‌  ‌
list1‌=‌‌[
‌‌"Hello‌"‌,
‌‌‌
"take‌"
‌]
‌‌‌
 
list2‌=‌‌[
‌‌"Dear"‌,‌‌
"Sir"‌
]‌‌
 
list3‌=‌‌[
‌i+j‌‌ for‌
‌i
‌‌‌
in‌
‌l
‌ist1‌f‌or‌
 
j‌‌
in‌
‌l
‌ist2]‌‌ 
print(list3)‌‌ 
 ‌
 ‌  ‌
 ‌  ‌
 ‌  ‌
 ‌  ‌

You might also like