Icon New game New game

Pure Python code

Quiz

Test your knowledge of pure Python code

Download the paper version to play

1 times made

Created by

Spain

Top 10 results

  1. 1
    00:50
    time
    20
    score
Do you want to stay in the Top 10 of this game? to identify yourself.
Make your own free game from our game creator
Compete against your friends to see who gets the best score in this game

Top Games

  1. time
    score
  1. time
    score
time
score
time
score
 
game-icon

Pure Python codeOnline version

Test your knowledge of pure Python code

by Álvaro Manuel Navarro Cruz
1

Which line is not correct? Pay attention to the indentation.

2

Is this correct if we want to generate a random number between 1 and 100?

3

Is it necessary to specify the last "elif" condition?

4

Which of the following statements about the filterEvenNumbers() function are correct?

Choose one or more answers

5

What is the purpose of the while loop in the timesTable program?

Feedback

If we leave line 5 in place, the if condition will be empty.

The function random.randint(a, b) generates a random integer including both endpoints a and b. So, random.randint(1, 98) will only generate numbers from 1 up to 98, excluding 99 and 100.

Using else here simplifies the code because all other possibilities have been eliminated by previous checks (if and elif). Since the only remaining case is that the number is equal, else handles it cleanly and reduces redundancy. This approach is common and accepted in programming to keep the code concise.

The while loop in the timesTable program is designed to repeatedly prompt the user to enter numbers and print the corresponding multiplication tables. The loop continues executing as long as the user does not enter the sentinel value -1. When the user inputs -1, the loop terminates, effectively stopping the repetition of multiplication tables. This allows the program to keep running and displaying new tables for different numbers until the user decides to stop by typing -1. Therefore, the purpose of the while loop is to keep printing multiplication tables until the user types -1.

educaplay suscripción