wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

R QCM3 5 boucles et conditions

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Quelle est la syntaxe correcte d'une boucle for en R ?

a)

for (i from 1 to 5) { print(i) }

b)

for i in 1 to 5 { print(i) }

c)

for (i in 1:5) { print(i) }

d)

for (i to 5) { print(i) }

2.

Quelle est la sortie de ce code : for (i in 1:3) { print(i^2) }

a)

1, 2, 3

b)

1, 4, 9

c)

2, 3, 4

d)

1, 8, 27

3.

Quelle est la structure correcte d'une condition if en R ?

a)

if [x > 10] { print("x est grand") }

b)

if (x > 10) { print("x est grand") }

c)

if x > 10 then print("x est grand")

d)

if {x > 10} print("x est grand")

4.

Que fait le code suivant ? x <- 5 if (x > 3) { print("x est supérieur à 3") } else { print("x est inférieur ou égal à 3") }

a)

Affiche "x est supérieur à 3"

b)

Affiche "x est inférieur ou égal à 3"

c)

Erreur de syntaxe

d)

Rien

5.

Quelle est la sortie de ce code : for (i in 1:4) { if (i %% 2 == 0) { print(i) } }

a)

1, 3

b)

2, 4

c)

1, 2, 3, 4

d)

2

6.

Quelle est la sortie de ce code : x <- 10 if (x < 5) { print("Petit") } else if (x == 10) { print("Exact") } else { print("Grand") }

a)

"Petit"

b)

"Exact"

c)

"Grand"

d)

Erreur

7.

Quelle boucle est utilisée pour parcourir les éléments d'un vecteur en R ?

a)

while

b)

for

c)

repeat

d)

next

8.

Quelle est la sortie de ce code : for (i in 1:5) { if (i == 3) { break } print(i) }

a)

1, 2, 3, 4, 5

b)

1, 2, 3

c)

1, 2

d)

1

9.

Que fait le code suivant : for (i in 1:4) { if (i == 2) { next } print(i) }

a)

Affiche 1, 2, 3, 4

b)

Affiche 1, 3, 4

c)

Affiche 2, 3, 4

d)

Affiche 1, 2, 3

10.

Comment ajouter une clause else dans une condition if ?

a)

else if {condition}

b)

if condition else

c)

else { instruction }

d)

else ( instruction )