For loop practice questions

Tell output (ofcourse without running the code):

Q.1.
s = “This city”
print(s[2:7])
print(s[:5])
print(s[3:0:-1])
print(s[0:5:2])
print(s[3:0:-2])

Q.2.
numbers = [1, 2, 3, 4, 5]
result = []
for num in numbers:
if num % 2 == 0:
result.append(num * 2)
else:
result.append(num)

Q.3.
l = [10,20,30,40]
l = [10,20,30,40]
for i in range(len(l)):
if i%2 == 0:
print(l[i]*2)
if i%3==0:
print(l[i]*3)
print(l[i]*10)

1 Like
  1. is ci
    This’ ’
    siT
    Ti’ ’
    sh

2.[1,4,3,8,5]
3).20
30
100
200
60
300
120
400

Q1.)Ans:
‘is ci’
'This ’
‘sih’
'Ti ’
‘sh’

Q2.)Ans: [1,4,3,8,5]

Q3.)Ans:
20
30
100
200
60
300
120
400

Q1.)Ans:
‘is ci’
'This ’
‘sih’
'Ti ’
‘sh’

Q2.)Ans: [1,4,3,8,5]

Q3.)Ans:
20
30
100
200
60
300
120
400

  1. is ci
    This’ ’
    sih
    Ti’ ’
    sh

  2. result = [1, 4, 3, 8, 5]

  3. 20
    30
    100
    60
    120
    400

  1. is ci
    This’ ’
    siT
    Ti’ ’
    sh

  2. result = [1, 4, 3, 8, 5]

  3. 20
    30
    100
    60
    120
    400

Q1)
‘is ci’
'This ’
‘sih’
'Ti ’
‘sh’

Q2) [1,4,3,8,5]

Q3)
20
30
100
200
60
300
120
400