CHAPTER 4 – VERY ABLE VARIABLES
MULTIPLE CHOICE QUESTIONS
- Which of the following is not a correct assignment in Python?
a. x = 10
b. _value = 25
c. 1st_number = 50
d. name = “Arjun”
- What will be the output of the following code?
a = 5
b = 2
print(a // b)
a. 2.5
b. 2
c. 3
d. Error
- If the input is
3for the following program, what is displayed?
num = int(input("Enter a number: "))
print(num ** 2)
a. 3
b. 6
c. 9
d. Error
- What will the following program print?
x = "Hello"
y = "World"
print(x + " " + y)
a. HelloWorld
b. Hello World
c. “Hello” + “World”
d. Error
- Which function is used to check the data type of a variable?
a. datatype()
b. typeof()
c. print()
d. type()
FILL IN THE BLANKS
- Variables are used to store __________ in a program.
- The operator
**is used for __________ in Python. - A string is always enclosed in __________ or __________.
- The function
int()is used to perform __________ casting. - Python is a __________ typed language, meaning variable types can change at runtime.
DESCRIPTIVE QUESTIONS
- Write a Python program to input two numbers and print their average.
- Explain the difference between
=(assignment operator) and==(comparison operator) with examples.
- Write a program that accepts the user’s name and age, then prints a message:
Hello <name>, you are <age> years old.
- What is the difference between
int,float, andstrdata types? Give one example of each.
- Explain why
my-variableis not a valid variable name in Python. Rewrite it correctly in two valid ways.
Answer Key
ANSWER KEY
MULTIPLE CHOICE QUESTIONS
- c. 1st_number = 50 (variable names cannot start with a digit)
- b. 2 (
5 // 2gives floor division result = 2) - c. 9 (
3 ** 2 = 9) - b. Hello World (
+with strings performs concatenation," "adds space) - d. type()
FILL IN THE BLANKS
- data / values
- exponentiation / power
- single quotes (‘ ’) or double quotes (“ ”)
- type / data type (string → integer)
- dynamically
DESCRIPTIVE QUESTIONS
- Program for average of two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
avg = (a + b) / 2
print("Average =", avg)
- Difference between
=and==
=is the assignment operator. Example:x = 10assigns 10 to x.==is the comparison operator. Example:x == 10checks if x is equal to 10, returnsTrueorFalse.
- Program for name and age message
name = input("Enter your name: ")
age = input("Enter your age: ")
print("Hello", name + ", you are", age, "years old.")
- Difference between int, float, str
int: whole numbers (e.g.,age = 25)float: decimal numbers (e.g.,temperature = 36.7)str: text (e.g.,name = "Arun")
- Invalid variable name correction
my-variableis invalid because-is not allowed in variable names.- Valid alternatives:
my_variable,myVariable
