Playing as a guest? to earn XP and track your progress.
๐ Getting Started with Python Quiz
๐ Getting Started with Python
What is a program?
A hardware device that runs code
A set of instructions given to a computer to perform a specific task
A type of memory
A file that stores images
A program is a set of instructions given to a computer to perform a specific task.
Which of the following is a low-level language?
Python
C++
Java
Assembly language
Machine language and assembly language are low-level (close to the hardware); Python, Java and C++ are high-level.
Why are high-level languages easier for humans to use?
They are close to human (English-like) language and easy to read, write and debug
They use only 0s and 1s
They work only on one type of computer
They run without any translator
High-level languages are English-like, so they are easy to read, write and debug.
Who created Python?
Dennis Ritchie
Bjarne Stroustrup
Guido van Rossum
James Gosling
Python was created by Guido van Rossum, a Dutch programmer.
In which year was Python first released?
2008
1991
1985
2000
Python was first released publicly in February 1991.
In which country was Python developed?
USA
Germany
India
The Netherlands
Python was created at CWI in the Netherlands.
Python is named after:
The comedy show 'Monty Python's Flying Circus'
A species of snake
A Greek god
Its creator's pet
Python is named after the BBC comedy show 'Monty Python's Flying Circus', not the snake.
Python was influenced by which two languages?
Java and Perl
BASIC and Pascal
ABC and Modula-3
C and C++
Python is based on (influenced by) the ABC language and Modula-3.
Which statement best describes Python?
A markup language for web pages
A high-level, interpreted, general-purpose, object-oriented language
A low-level, compiled, hardware-specific language
A database query language
Python is a high-level, interpreted, general-purpose, object-oriented programming language.
Which Python version series is in current use?
Python 0.9
Python 1.x
Python 2.x
Python 3.x
The current series is Python 3.x; Python 3.0 came in 2008 and Python 2 ended in 2020.
Django and Flask are Python tools used mainly for:
Web development
Data visualisation
Machine learning
Game development
Django and Flask are used to build websites and web applications.
Which is NOT listed as an advantage (plus) of Python?
Easy to use
Free and open source
Fastest execution of all languages
Cross-platform
Python is not the fastest language โ being interpreted, it is slower than compiled languages such as C/C++.
Python is called an 'expressive language' because:
It needs no indentation
Fewer lines of code do more work
It prints colourful output
It uses emojis in code
In Python, fewer lines of code do more work โ for example, swapping two variables takes one line.
What is the output of this code?
a, b = 5, 10 a, b = b, a print(a, b)
5 10
10 10
Error
10 5
a, b = b, a swaps the two values, so a becomes 10 and b becomes 5.
The phrase 'batteries included' describes which feature of Python?
Its completeness โ a large standard library comes built in
It runs on laptops only
It saves battery power
It is free of cost
'Its completeness' means a huge standard library (math, random, statistics and more) comes with Python.
Python being 'cross-platform' means:
It needs a separate version of the code for each OS
It works only on Windows
The same program runs on Windows, Linux and macOS without changes
It can cross-compile to C
Cross-platform (platform independent) means the same Python program runs on different operating systems unchanged.
Which of these is a limitation (minus) of Python?
It is free and open source
It is not strong on type-binding
It has simple syntax
It is used for AI
Python is not strong on type-binding: a variable can hold any type, and some type mismatch errors are caught only at runtime.
Why is converting a Python program to another language considered difficult?
Python programs are too short
Python has no variables
Python code is encrypted
Python's syntax is quite different from other languages
'Not easily convertible' โ Python's syntax differs a lot from other languages, so translating it is not easy.
In which area does Python have fewer libraries compared with older languages?
Mobile app development
Data science
Machine learning
Web development
Python has lesser libraries in some specialised areas, such as mobile app development.
A student writes 'Python is a compiled language.' Why is this wrong?
Python has no translator at all
Python is a markup language
Python is interpreted: its bytecode is executed by the PVM, not turned into a stand-alone machine code file
Python is compiled only on Linux
Python is an interpreted language. Source code becomes bytecode, which the Python Virtual Machine interprets.
A compiler translates:
One line at a time while running
The whole program into machine code at once
Machine code into source code
Only the comments
A compiler translates the entire program into machine code at once and then runs it.
How does an interpreter handle errors?
It reports all errors together after translation
It fixes errors automatically
It ignores all errors
It stops at the first error it finds
An interpreter translates and executes line by line, so it stops as soon as it hits the first error.
Which statement comparing compilers and interpreters is correct?
Compiled programs usually run faster, but interpreted programs are easier to debug
Both translate one line at a time
Interpreted programs usually run faster
Python uses a compiler only
Compiled code runs faster because it is already translated; interpreters are slower but make debugging easier.
In the translator analogy, an interpreter is like:
A dictionary
A translator who translates a whole book first
A live translator translating each sentence as soon as it is spoken
A typist
An interpreter works like a live translator, handling one sentence (statement) at a time.
Which is the correct execution flow of a Python program?
Source code โ PVM โ Bytecode โ Output
Source code โ Bytecode โ PVM โ Output
Bytecode โ Source code โ Output
Source code โ Machine code file โ Output
Source code (.py) is compiled internally to bytecode, which the Python Virtual Machine executes to give the output.
What does PVM stand for?
Private Virtual Memory
Python Visual Monitor
Program Verification Module
Python Virtual Machine
PVM is the Python Virtual Machine, which reads and executes bytecode.
Which file extension is sometimes used for Python bytecode files?
.pyc
.pvm
.exe
.py
Bytecode is sometimes saved as .pyc files; source code uses .py.
What makes Python programs cross-platform?
Every OS includes the same compiler
Python avoids using the CPU
Bytecode is platform-independent and can run on any computer that has a PVM
Python code is converted to Windows machine code
Bytecode is platform-independent; any computer with a PVM can run it, and the PVM deals with the hardware.
What is the extension of a Python source file?
.pt
.py
.pyt
.python
Python source files use the .py extension.
What is the full form of IDLE?
Interactive Debugging and Learning Engine
Internal Development Logic Environment
Integrated Development Language Editor
Integrated Development and Learning Environment
IDLE stands for Integrated Development and Learning Environment โ the default editor that comes with Python.
Which part of IDLE shows the >>> prompt and runs commands immediately?
Python Shell
File menu
Editor window
Debugger
The Python Shell shows the >>> prompt and works in Interactive Mode.
What is the IDLE feature that shows keywords, strings and comments in different colours?
Debugger
Auto-save
Syntax colouring
Bytecode viewer
Syntax colouring displays different parts of the code in different colours, making it easier to read.
Which tool is a free Python distribution with many data-science packages pre-installed?
Notepad
Anaconda
IDLE
PyCharm
Anaconda is a free Python distribution with many data-science packages; Spyder comes with it.
Which tool is web-based and lets you write code and see its output in 'cells'?
PyCharm
Spyder
Visual Studio Code
Jupyter Notebook
Jupyter Notebook is a web-based tool where code and output appear in cells.
What is the >>> symbol in the Python shell called?
The chevron or primary prompt
The comment symbol
The output marker
The error sign
is the Python prompt (chevron), showing that Python is ready to accept a command in Interactive Mode.
In Interactive Mode, what is shown after typing 7 / 2 at the >>> prompt?
3.0
Error
3.5
3
The / operator performs division, so 7 / 2 gives 3.5.
What is the main disadvantage of Interactive Mode?
It cannot do arithmetic
Commands cannot be saved for later use
It needs internet access
It shows results too slowly
In Interactive Mode the commands are not saved, so they must be retyped; it is not suitable for long programs.
How can you leave the Python shell?
Press F5
Type close
Type stop()
Type exit() or quit()
Typing exit() or quit() leaves the Python shell.
In Script Mode, a program is:
Written in a file, saved with a .py extension, and run as a whole
Run without being saved
Written in binary
Typed one statement at a time and run immediately
In Script Mode the complete program is written in the editor, saved as a .py file and executed as a whole.
Which key runs a program (Run โ Run Module) in IDLE?
F1
Esc
F5
Ctrl+S
Run โ Run Module, or pressing F5, runs the saved program; the output appears in the Python Shell.
What is the correct order of steps to run a program in IDLE's Script Mode?
Type at >>> then press F5
File โ New File, type the program, File โ Save, Run โ Run Module
Run โ Save โ Type โ New File
Save โ New File โ Run โ Type
Open a new file, type the program, save it as name.py, then run it with Run โ Run Module (F5).
A friend typed a long program in the Python shell and wants to run it again tomorrow. What should they do?
Take a screenshot of the shell
Use a longer prompt
Nothing โ the shell saves it automatically
Write it in Script Mode and save it as a .py file
Shell commands are not saved. Script Mode saves the program as a .py file that can be re-run any time.
Interactive Mode is best suited for:
Testing small pieces of code and quick calculations
Saving projects
Writing long programs
Creating .pyc files
Interactive Mode gives instant results, so it is ideal for testing small code and using Python as a calculator.
What is the output of this program?
name = "Riya" print("Hello,", name)
Hello, name
Hello,Riya
Hello, Riya
"Hello," Riya
Items separated by commas are printed with a space between them: Hello, Riya.
What is the output of print("5 + 3")?
"5 + 3"
5 + 3
Error
8
Text inside quotes is printed exactly as it is, so it prints 5 + 3.
What is the output of print("Total =", 5 * 3)?
Total =15
Total = 5 * 3
Total15
Total = 15
5 * 3 is evaluated to 15, and the comma adds a space: Total = 15.
What happens when you run Print("Hi")?
NameError: name 'Print' is not defined
Nothing happens
It prints "Hi"
It prints Hi
Python is case-sensitive; Print is not the same as print, so a NameError is raised.
When printing text (a string) with print(), the text must be:
Written in capital letters
Followed by a semicolon
Enclosed in single or double quotes
Written after a # symbol
Strings must be enclosed in single or double quotes, e.g. 'Hi' or "Hi".
When multiple items are separated by commas in print(), they are printed:
On separate lines
With a space between them
Joined with no space
With a comma between them
print() separates multiple items with a space.
What does Python do with a line that starts with #?
Prints it
Runs it twice
Raises an error
Treats it as a comment and ignores it
Lines starting with # are comments; Python ignores them โ they explain the code to humans.
What error occurs if a top-level statement starts with an unexpected space?
IndentationError
NameError
TypeError
No error
Top-level statements must start at the beginning of the line; an unexpected leading space gives an IndentationError.
Which of these Python libraries/tools is used for AI and machine learning?
Flask
Django
TensorFlow
Pygame
TensorFlow and scikit-learn are used for AI and machine learning.