首页 > > 详细

辅导 COMP1117A LOOPS AND ITERATIONS Tutorial 4讲解 R语言

COMP1117A Tutorial 4

LOOPS AND ITERATIONS

Q1

What is the output of the following program?

for i in range(5):

print(i, end=',')

A. 1,2,3,4,5,

B. 0,1,2,3,4,

C. 0,1,2,3,4,5,

D. 0 1 2 3 4

Q2

What is the output of the following program?

x = 'abcd'

while j in x:

print(j, end=' ')

A. abcd

B. a b c d

C. abcdabcdabcdabcd

D. Error

Q3

What is the output of the following program?

x = 'abcd'

j = 'j'

while j in x:

print(j, end = ' ')

A. no output

B. j j j j j…(never stop)

C. a b c d

D. abcd

Q4

What is the output of the following program?

x = 'abcd'

j = 'a'

while j in x:

print(j, end = ' ')

A. no output

B. j j j j j…(never stop)

C. a a a a…(never stop)

D. a

Q5

What is the output of the following program?

i = 1

while (i < 12):

print(i, end = ' ')

i += 2

A. 1

B. 2 4 6 8 10

C. 1 2 3 4 5 6

D. 1 3 5 7 9 11

Q6

What is the output of the following program:

for i in range(0,5,-1):

print(i,end = ' ')

A. Error: invalid syntax

B. Nothing will be printed

C. 5 4 3 2 1

D. 0 -1 -2 -3 …(never stop)

Q7

What is the output of the following program?

x=2

for i in range(x):

x+=1

print(x, end = ' ')

A. 0 1 2 3 4 …(never stop)

B. 0 1 2 3

C. 0 1

D. 3 4

Q8

What is the output of the following program?

for i in range(1,4):

print(i,end = ' ')

i = i-1

A. 1 2 3

B. 1 0 -1

C. 1 0 -1 …(never stop)

D. Nothing is printed

Q9

What is the output of the following program?

x = 'abcd'

for i in range(x):

print(i, end=' ')

A. a b c d

B. abcd

C. abcdabcdabcdabcd

D. Error





联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!