Python Programming Basics
- 31Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary reason to learn programming according to the content?
What is the primary reason to learn programming according to the content?
31 questions
- 1
What is the primary reason to learn programming according to the content?
- A
To become a professional software developer
- B
To take an idea in your head and turn it into a series of steps the computer can execute
- C
To create video games exclusively
- D
To earn money by writing code
Correct answer
BTo take an idea in your head and turn it into a series of steps the computer can execute
Explanation
The video states programming allows you to take an idea, turn it into steps the computer can understand and execute. Other options are too narrow or not mentioned.
- A
- 2
According to the content, what percentage of viewers wanted to learn Python?
- A
65%
- B
75%
- C
50%
- D
80%
Correct answer
A65%
Explanation
The video mentions that 65% of viewers wanted Python, making it the clear winner.
- A
- 3
Which of the following is NOT a reason given for choosing Python?
- A
It is concise and easy to use
- B
It has been around for a while
- C
It is a good general-purpose language
- D
It compiles faster than other languages
Correct answer
DIt compiles faster than other languages
Explanation
Python is interpreted, not compiled, and speed of compilation is not mentioned as a reason. The other options are explicitly stated.
- A
- 4
How do you check if Python is installed on Windows 10 using command prompt?
- A
Type 'python version'
- B
Type 'python -v'
- C
Type 'version python'
- D
Type 'python --version'
Correct answer
DType 'python --version'
Explanation
The video shows typing 'python --version' to check the installed version.
- A
- 5
During installation, what important option must be checked before clicking 'Install Now'?
- A
Create desktop shortcut
- B
Install debugging symbols
- C
Add Python to PATH
- D
Install for all users
Correct answer
CAdd Python to PATH
Explanation
The video specifically mentions checking 'Add Python to PATH' to ensure proper functionality.
- A
- 6
What is the file extension for Python files?
- A
.py
- B
.pn
- C
.pyth
- D
.pt
Correct answer
A.py
Explanation
The video states that the extension for Python is .py, just like .txt is for text files.
- A
- 7
What happens when you type '1 + 2' in the Python terminal?
- A
It asks for confirmation
- B
It shows a syntax error because spaces are not allowed
- C
It evaluates the expression and returns 3
- D
It displays '1 + 2' as a string
Correct answer
CIt evaluates the expression and returns 3
Explanation
The video shows that typing 1 + 2 evaluates to 3. Spaces are allowed and do not cause errors.
- A
- 8
Which operator is used for exponentiation in Python?
- A
**
- B
^
- C
exp
- D
^
Correct answer
A**
Explanation
The video demonstrates that 2 asterisks () are used for exponentiation, e.g., 22 equals 4.
- A
- 9
What does the floor division operator '//' do?
- A
Returns the remainder of division
- B
Returns the rounded result
- C
Returns the quotient without remainder
- D
Returns a floating-point result
Correct answer
CReturns the quotient without remainder
Explanation
The video explains that '//' performs floor division, giving the quotient without the remainder. Example: 5//2 gives 2.
- A
- 10
Which operator gives the remainder of division?
- A
mod
- B
//
- C
%
- D
/
Correct answer
C%
Explanation
The modulus operator % returns the remainder, e.g., 5 % 2 returns 1.
- A
- 11
Why would you use double quotes around a string that contains a single quote?
- A
Double quotes are always required for strings
- B
To distinguish it from other strings
- C
To avoid a syntax error because the single quote would end the string prematurely
- D
To make the string print faster
Correct answer
CTo avoid a syntax error because the single quote would end the string prematurely
Explanation
The video illustrates that using double quotes allows a single quote inside the string without causing a syntax error, since Python would interpret a single quote as the end of the string.
- A
- 12
What symbol is used to create a comment in Python?
- A
/*
- B
- C
- D
//
Correct answer
BExplanation
The video shows that the hash symbol (#) is used for comments. Comments are ignored during execution.
- A
- 13
Which of the following is a valid variable name in Python?
- A
2things
- B
class
- C
my_variable
- D
my variable
Correct answer
Cmy_variable
Explanation
Variable names can contain letters, numbers, and underscores but cannot start with a number or contain spaces. 'class' is a reserved keyword. Only 'my_variable' is valid.
- A
- 14
In Python, how do you assign a value to a variable?
- A
Use := for assignment
- B
Use = for assignment
- C
Use == for assignment
- D
Use <- for assignment
Correct answer
BUse = for assignment
Explanation
The equals sign (=) is used for assignment. Double equals (==) is for equality comparison.
- A
- 15
What is the output of the following code? x = 'Hello' x = 5 print(x)
- A
Error
- B
Hello5
- C
5
- D
Hello
Correct answer
C5
Explanation
The variable x is first assigned 'Hello', then reassigned to 5. The last assignment overwrites the previous, so print(x) outputs 5.
- A
- 16
What function deletes a variable in Python?
- A
remove
- B
rm
- C
delete
- D
del
Correct answer
Ddel
Explanation
The 'del' keyword is used to delete a variable, as shown in the video with 'del red_bucket'.
- A
- 17
How do you get user input in Python?
- A
Using the prompt() function
- B
Using the readline() function
- C
Using the input() function
- D
Using the getch() function
Correct answer
CUsing the input() function
Explanation
The video demonstrates using the input() function to prompt the user and assign the entered value to a variable.
- A
- 18
Which operator checks if two values are not equal?
- A
!=
- B
==
- C
<>
- D
not =
Correct answer
A!=
Explanation
The video shows that '!=' is the not-equal operator, as in '5 != 4' returns True.
- A
- 19
What is the correct syntax for an if statement in Python?
- A
if x < 5 do ...
- B
if x < 5 then ...
- C
if x < 5: ...
- D
if (x < 5) { ... }
Correct answer
Cif x < 5: ...
Explanation
Python uses a colon after the condition and indentation for the block. No parentheses or braces are required for the condition.
- A
- 20
What keyword is used for an 'else if' condition in Python?
- A
elseif
- B
elsif
- C
else if
- D
elif
Correct answer
Delif
Explanation
The video demonstrates 'elif' as the keyword for else if conditions.
- A
- 21
In the school age calculator example, what would be output if age is 3 and name is 'Thomas'?
- A
Enjoy the time, Thomas is only 3
- B
They grow up so fast!
- C
Error: age not valid
- D
Enjoy kindergarten, Thomas
Correct answer
AEnjoy the time, Thomas is only 3
Explanation
The function checks if age is less than 5 first. For age=3, it prints 'Enjoy the time, Thomas is only 3'.
- A
- 22
What keyword is used to define a function in Python?
- A
def
- B
define
- C
func
- D
function
Correct answer
Adef
Explanation
The video shows that 'def' is used to define a function, e.g., 'def my_function():'.
- A
- 23
What does a function's return statement do?
- A
Defines a parameter
- B
Exits the function and sends a value back to the caller
- C
Prints a value to the console
- D
Stops the program
Correct answer
BExits the function and sends a value back to the caller
Explanation
The video explains that 'return' sends a value back from the function to where it was called, e.g., returning new_age.
- A
- 24
Which of the following is NOT a type of loop mentioned in the video?
- A
Loop with if and break
- B
Do-while loop
- C
While loop
- D
For loop
Correct answer
BDo-while loop
Explanation
The video covers while loops and for loops. Do-while loops are not mentioned or used in Python.
- A
- 25
In a while loop, what happens if the condition never becomes false?
- A
The loop terminates automatically after 100 iterations
- B
The loop executes exactly once
- C
Python throws an error
- D
The loop creates an infinite loop
Correct answer
DThe loop creates an infinite loop
Explanation
The video warns about infinite loops if the condition never becomes false, as when incrementing is forgotten.
- A
- 26
What statement is used to exit a loop immediately?
- A
exit
- B
stop
- C
continue
- D
break
Correct answer
Dbreak
Explanation
The video demonstrates 'break' to stop the loop entirely, e.g., when d == 'Thursday'.
- A
- 27
What statement is used to skip the current iteration and continue with the next?
- A
skip
- B
pass
- C
next
- D
continue
Correct answer
Dcontinue
Explanation
The video shows 'continue' to skip the rest of the current iteration and move to the next, e.g., skipping Thursday but continuing with Friday.
- A
- 28
How do you use a library in Python?
- A
Using the 'using' keyword
- B
Using the 'import' keyword
- C
Using the 'require' keyword
- D
Using the 'include' keyword
Correct answer
BUsing the 'import' keyword
Explanation
The video demonstrates importing the math library with 'import math' to access pi.
- A
- 29
What kind of error occurs when you type 'print(Hello World)' without quotes?
- A
Semantic error
- B
Logic error
- C
Runtime error
- D
Syntax error
Correct answer
DSyntax error
Explanation
The video labels this as a syntax error because it violates Python's grammar rules. The error message says 'name error' but it's classified as syntax error (incorrect syntax).
- A
- 30
Dividing by zero in Python produces which type of error?
- A
Syntax error
- B
ZeroDivisionError (runtime error)
- C
Semantic error
- D
TypeError
Correct answer
BZeroDivisionError (runtime error)
Explanation
The video shows that 10/0 results in a ZeroDivisionError, which is a runtime error occurring during execution.
- A
- 31
What type of error is hardest to troubleshoot because the code runs but produces incorrect results?
- A
Semantic error
- B
Compiler error
- C
Syntax error
- D
Runtime error
Correct answer
ASemantic error
Explanation
The video describes semantic errors as the hardest because the syntax is correct and the program runs, but the output is not as expected.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.