MCQs
- What is the output of print(“Hello” + “ “ + “World”)?
a) HelloWorld b) Hello World c) Hello+World d) Error - What type of value does the input() function return?
a) Integer b) Float c) String d) Boolean - Which of the following is NOT a step in the basic programming process?
a) Write Code b) Compile/Interpret c) Execute d) Ignore Errors - Which operator has the highest precedence in Python?
a) Addition (+) b) Multiplication (*) c) Exponentiation (**) d) Parentheses () - Which of the following is a comparison operator in Python?
a) += b) == c) ** d) // - What is the result of 10 % 3 in Python?
a) 3 b) 3.33 c) 1 d) 0 - What does floor division // return?
a) The remainder b) The integer part of the quotient c) A float always d) The product - What is the output of print(10 // 3)?
a) 3.333 b) 3 c) 1 d) 4 - What does the logical ‘not’ operator in Python return?
a) The sum of two values b) The opposite boolean value c) A comparison result d) A string - After parentheses, which operator has the highest precedence in Python?
a) Addition + b) Multiplication * c) Exponentiation ** d) Modulus % - Python comments begin with # and are:
a) Executed as code b) Ignored by the interpreter c) Stored in memory d) Printed automatically - Which Python data type is used to store True or False?
a) Integer b) Float c) String d) Boolean - What is the output of the following code? age = 25; print(“ Age : “, age)
a) Age: 25 b) 25 c) Age d) age - What is the result of 5 > 3 and 2 < 1?
a) True b) False c) Error d) None - The str() function converts a value into which type?
a) Integer b) String c) Float d) Boolean - Which of the following is NOT a valid comparison operator in Python?
a) >= b) != c) => d) == - PyCharm, VS Code, and IDLE are examples of which of the following?
a) IDEs (Integrated Development Environments) b) Web browsers c) Databases d) Operating systems - What is an f-string in Python used for?
a) Formatting floating-point numbers only b) Embedding variables/expressions inside a string (string interpolation) c) Creating new files d) Importing libraries - Google Colab is a cloud-based Python environment, which means:
a) No installation is needed b) It requires installation c) It only works offline d) It requires a USB drive - Which of the following is a valid Python variable name?
a) 2myVar b) my-var c) my_var d) my var - Which symbol is used to write comments in Python?
a) // b) /* c) # d) — - Python is called a versatile language, which means that it:
a) Only works on one platform b) Is very slow c) Can only be used for games d) Applies to many different fields - Which function converts a string into an integer?
a) str() b) int() c) float() d) input() - From which website can Python be downloaded?
a) python.org b) python.com c) code.python.net d) download.pyin - Exponentiation ** in Python is right-associative, so what does 2 ** 3 ** 2 equal?
a) 64 b) 512 c) 36 d) 8 - What should you do while installing Python so that it can be run from the command line more easily?
a) Uncheck “Add Python to PATH” b) Choose a different IDE c) Check “Add Python to PATH” d) Install only the IDE - What is the output of print(type(3.14))?
a) <class ‘int’> b) <class ‘str’> c) <class ‘bool’> d) <class ‘float’> - What does the /= operator do in Python?
a) Compares two values b) Multiplies and assigns c) Adds and assigns d) Divides and assigns the result - What is the function of the += operator?
a) Adds two numbers b) Compares values c) Adds and assigns d) Multiplies values - In what form does input() in Python always return data?
a) Integer b) Float c) String d) Boolean
Short Questions
(i) What are the three logical operators in Python?
(ii) What is the difference between / (division) and // (floor division)?
(iii) What does the % operator do in Python? Give an example.
(iv) What is string interpolation using f-strings in Python? Give an example.
(v) Write the PEMDAS operator precedence order in Python.
(vi) What is the result of True and False in Python?
(vii) What is the purpose of the print() statement in Python?
(viii) What are the four main Python data types? Give one example of each.
(ix) What is the float() function used for?
(x) Discuss three basic data types in Python.
(xi) How do you convert a string input to an integer in Python? Write code.
(xii) What is Python, and name three fields where it is used?
(xiii) What are logical operators, and name all three?
(xiv) What is an IDE? Name three Python IDEs from the chapter.
(xv) How do you display multiple values with one print statement in Python?
(xvi) What is operator precedence? Give an example.
(xvii) What is the difference between = (assignment) and == (comparison)?
(xviii) What does exponentiation ** do in Python? Give an example.
(xix) How do you get user input in Python?
(xx) Write any three main rules for naming variables in Python.
(xxi) Give one example each of an arithmetic, comparison, and assignment operator.
(xxii) What are three rules for naming variables in Python?
(xxiii) How does the if statement differ from the if-else statement?
(xxiv) What is Google Colab, and what is its main advantage?
(xxv) Why are comments important in programming?
(xxvi) What is the difference between float and integer data types?
(xxvii) What happens if you try to add a string and an integer in Python without converting?
(xxviii) Describe the difference between integer and float data types in Python.
(xxix) Why must ‘Add Python to PATH’ be checked during installation?
(xxx) What is the purpose of comments in Python code?
Long Questions
- What are arithmetic operators in Python? Provide examples of each operator and explain when you would use them.
- Write a program in Python that will take a name from the user and display a greeting message to the given name.
- What are the basic data types in Python? Explain integers, floats, strings, and Booleans with examples.
- Explain the input() and print() functions with examples.
- Write a program in Python that takes five numbers from the user and displays their average.
- Write a program in Python that takes two numbers from the user and displays their sum.
- Solve the following expressions: a) 8 + 3 * 4 – 2 ** 2 b) 20 % 7 * 3 + 10 // 3 c) 2 * 3 ** 2 % 4 + 10 – 6 / 2
- Explain how comparison and logical operators work together in conditional statements. Provide a practical example.
Answer Key
- b) Hello World
- c) String
- d) Ignore Errors
- d) Parentheses ()
- b) ==
- c) 1
- b) The integer part of the quotient
- b) 3
- b) The opposite boolean value
- c) Exponentiation **
- b) Ignored by the interpreter
- d) Boolean
- a) Age: 25
- b) False
- b) String
- c) =>
- a) IDEs (Integrated Development Environments)
- b) Embedding variables/expressions inside a string (string interpolation)
- a) No installation is needed
- c) my_var
- c) #
- d) Applies to many different fields
- b) int()
- a) python.org
- b) 512
- c) Check “Add Python to PATH”
- d) <class ‘float’>
- d) Divides and assigns the result
- c) Adds and assigns
- c) String
