1 2 3 4 For I in Range (1,5) : For J in Range (1, I+1) : Print (J," ", End " ") Print ('/N')

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DAY 1 : STRINGS & LOOPS BASED QUESTIONS

Predict the Output for the following:

(1)

1
for i in range(1,5):

2
 for j in range(1,i+1):

3
  print(j," ", end=" ")

4
 print('\n')

1 2

1 2 3

1 2 3 4

(2)

1
country = 'INDIA'

2
for i in country:

3
 print (i)

(3)

1
country = 'INDIA'

2
i=0

3
while i<len(country):

4
 print (i+1,country[i])
5
 i=i+1

1 I

2 N

3 D

4 I

5 A

(4)

1
var = 7

2
while var > 0:

3
  print ('Current variable value: ', var)

4
  var = var -1

5
  if var == 3:

6
    for i in "abc":

7
      print(i*var)

8
    break

9
  else:

10
    if var == 6:

11
      var = var -1

12
      continue

13
print ("Good bye!")

Current variable value: 7

Current variable value: 5

Current variable value: 4

aaa

bbb

ccc

Good bye!

(5)
Which of the following statement(s) would give an error
after
executing the following code?

(a) Statement 3

(b) Statement 4

(c) Statement 5

(d) Statement 4 and 5

1 S="Welcome to class XI" # Statement 1
2 print(S) # Statement 2
3 S="Thank you" # Statement 3
4 S[0]= '@' # Statement 4
5 S=S+"Thank you" # Statement 5

Welcome to class XI

-----------------------------------------------------
----------------------

TypeError Traceback
(most recent call last)

<ipython-input-10-61dc471ce75f> in <module>

2 print(S) # Statement 2

3 S="Thank you" # Statement 3

----> 4 S[0]= '@' # Statement 4

5 S=S+"Thank you" # Statement 5

TypeError: 'str' object does not support item


assignment

You might also like