Parho

Class 10 Computer Science · Chapter 3

Introduction to Python Programming: questions and answers

Every short question, long question and MCQ on this chapter's free papers, each with its answer. Try one yourself first, then check.

47short questions
9long questions
0MCQs

Short questions with answers

  1. Q1 · 2 marks

    What is Python and why is it popular?

    Answer

    Python is a widely-used high-level programming language famous for its simplicity and readability. It is versatile and applicable to web development, data analysis, and artificial intelligence, and its user-friendly nature helps you get started quickly and efficiently.

  2. Q2 · 2 marks

    Define computer programming.

    Answer

    Computer programming is the process of creating a set of instructions that tell a computer how to perform a task. These instructions are written in a programming language that the computer can understand and execute.

  3. Q3 · 2 marks

    Explain the example of giving directions to a friend in relation to programming.

    Answer

    Programming is like giving directions to a friend on how to reach your house. You need to be clear and precise so your friend does not get lost. Similarly, when we write programs, we give clear and precise instructions to the computer to complete specific tasks.

  4. Q4 · 2 marks

    What is a development environment?

    Answer

    The development environment refers to the process of preparing a computer to write, run, and debug Python code effectively. It involves installing and configuring the necessary software, tools, and libraries.

  5. Q5 · 2 marks

    Write the steps to install Python.

    Answer

    Visit python.org, go to the Downloads section and click the latest version for your operating system; the installer downloads automatically. Run the downloaded .exe file, check the box Add Python to PATH, select Install Now (or customize the installation), wait for it to complete, then click Close.

  6. Q6 · 2 marks

    Why should Add Python to PATH be checked while installing Python?

    Answer

    Checking Add Python to PATH makes it easier to run Python from the command line.

  7. Q7 · 2 marks

    Name the IDE options for Python and the editions of PyCharm.

    Answer

    The IDE options are PyCharm, VS Code, and IDLE (included with Python). PyCharm is a powerful IDE for Python development available in a free Community edition or a paid Professional edition.

  8. Q8 · 2 marks

    How do you configure PyCharm with Python?

    Answer

    Open PyCharm and start a new project; in the Configure or Settings menu go to Project Interpreter; click the gear icon, select Add Interpreter, and choose the path to your Python executable (e.g., C:\Python312\python.exe on Windows or /usr/bin/python3 on Linux/macOS); apply the settings and let PyCharm index the interpreter.

  9. Q9 · 2 marks

    How do you test that the IDE is correctly configured?

    Answer

    Create a new file (e.g., test.py), write the script print('Hello, Python!'), and run it (the Run button in PyCharm/IDLE or F5 in VS Code after setting up a task). If the output Hello, Python! appears, the IDE is correctly configured.

  10. Q10 · 2 marks

    What is Google Colab and what are its advantages?

    Answer

    Google Colab is a free cloud-based platform that provides a Jupyter notebook environment with pre-installed Python and popular libraries like NumPy, Pandas, and Matplotlib. It requires no local installation, so it is ideal for beginners or machines with limited resources. You sign in with a Google account, create a new notebook, and write and execute code in cells.

  11. Q11 · 2 marks

    Why are comments important in programming?

    Answer

    Comments are lines that are not executed by the Python interpreter. They provide explanations or notes for the programmer and improve code readability. Single-line comments start with the # symbol.

  12. Q12 · 2 marks

    How can multiline comments be written in Python?

    Answer

    Triple quotes can be used for multiline comments, but actually they are multiline string literals which are ignored at runtime.

  13. Q13 · 2 marks

    What is a variable in Python?

    Answer

    A variable functions as a storage container within a computer's memory. It allows the storage of data that can be retrieved later in the code.

  14. Q14 · 2 marks

    Why is it called a variable? Explain with the age example.

    Answer

    The value of a variable can change throughout the execution of a program. In the example, age = 71 is printed as Azam lived for 71 years, then age = 60 is assigned and printed as Iqbal lived for 60 years.

  15. Q15 · 2 marks

    Write any three main rules for naming variables in Python?

    Answer

    (1)The name must begin with a letter (a-z, A-Z) or an underscore.

    (2)Subsequent characters can include letters, digits (0-9), or underscores.

    (3)Variable names are case-sensitive, so age and Age are different variables.

    (4)Reserved keywords such as for, while, if cannot be used as variable names.

  16. Q16 · 2 marks

    Name some reserved words in Python that cannot be used as variable names.

    Answer

    Some reserved words are: if, else, elif, for, while, break, continue, and, or, not, in, is, True, False, None.

  17. Q17 · 3 marks

    Discuss three basic data types in python.

    Answer

    Integer (int) stores whole numbers, e.g. age = 17. Floating-point (float) stores decimal numbers, e.g. price = 19.99. String (str) stores text, e.g. name = 'Ali'. (Boolean (bool) stores True or False, e.g. is_student = True.)

  18. Q18 · 2 marks

    Describe the difference between integer and float data types in Python.

    Answer

    An integer (int) stores whole numbers without a decimal point, e.g. age = 17. A float (floating-point) stores decimal numbers, e.g. price = 19.99.

  19. Q19 · 2 marks

    How do you get user input in Python?

    Answer

    We use the input() function. It displays a message on the screen, waits for the user to type something and press Enter, and the text entered is stored in a variable.

    Example: name = input('Enter your name: ').

  20. Q20 · 2 marks

    What is the purpose of print() statement in Python?

    Answer

    The print() function is used to display information on the screen. It takes one or more arguments and displays them.

    Example: print('Hello, ' + name + '!') displays a greeting that includes the user's name.

  21. Q21 · 2 marks

    How are integer and float inputs handled in Python?

    Answer

    The int() or float() functions are used to convert input strings to integers or floating-point numbers.

    Example: user_age = int(input('Enter your age: ')) and user_height = float(input('Enter your height in meters: ')).

  22. Q22 · 2 marks

    Are age and Age the same variable in Python? Explain.

    Answer

    No. Variable names in Python are case-sensitive, so age and Age are considered two different variables.

  23. Q23 · 2 marks

    What is the role of indentation in Python?

    Answer

    In Python, indentation defines the structure and scope of your code. Incorrect indentation may cause errors in your code.

  24. Q24 · 2 marks

    What are operators and operands?

    Answer

    Operators are symbols that perform operations on operands (the values or variables they work on).

  25. Q25 · 2 marks

    What is an expression in Python?

    Answer

    An expression is a combination of operators and values that produces a result.

  26. Q26 · 2 marks

    Name the arithmetic operators in Python.

    Answer

    Addition (+), subtraction (-), multiplication (*), division (/), floor division (//), modulus (%), and exponentiation (**).

  27. Q27 · 2 marks

    If a = 10 and b = 3, what are the results of a / b and a // b?

    Answer

    a / b = 3.3333333333333335 (division returns a decimal), while a // b = 3 (floor division).

  28. Q28 · 2 marks

    What are the modulus and power operators? Give the result for a = 10 and b = 3.

    Answer

    The modulus operator % gives the remainder: 10 % 3 = 1. The operator is the power operator: 10 3 = 1000.

  29. Q29 · 2 marks

    What are comparison operators and what do they return?

    Answer

    Comparison operators are used to compare two values or expressions (equality, inequality, greater than, less than, etc.). They return a Boolean value (True or False). They are >, <, ==, !=, >=, <=.

  30. Q30 · 3 marks

    For x = 10 and y = 5, give the result of each comparison operator.

    Answer

    10 > 5 = True; 10 < 5 = False; 10 == 5 = False; 10 != 5 = True; 10 >= 5 = True; 10 <= 5 = False.

  31. Q31 · 2 marks

    What is the difference between = and == in Python?

    Answer

    = is the assignment operator that assigns the value on the right to the variable on the left. == is a comparison operator that checks whether two values are equal and returns True or False.

  32. Q32 · 2 marks

    What are assignment operators? Give examples.

    Answer

    Assignment operators are used to assign values to variables. The most common is the equal sign (=), which assigns the value on the right to the variable on the left. Compound assignment operators like +=, -=, *=, and /= combine arithmetic operations with assignment (also //=, %=, **=).

  33. Q33 · 3 marks

    For a = 10 and b = 5, find a after a += b, a -= b, a *= b and a /= b applied one after another.

    Answer

    a += b gives 15; a -= b gives 10; a *= b gives 50; a /= b gives 10.0.

  34. Q34 · 3 marks

    If a = 10.0 and b = 5, find a after a //= b, a %= b and a **= b applied one after another.

    Answer

    a //= b gives 2.0; a %= b gives 2.0; a **= b gives 32.0.

  35. Q35 · 2 marks

    What are logical operators and name all three?

    Answer

    Logical operators are used to combine multiple expressions and return Boolean values based on the evaluation of the expressions. The three most common logical operators are and, or, and not.

  36. Q36 · 2 marks

    If x = True and y = False, give the results of x and y, x or y, not x and not y.

    Answer

    x and y = False; x or y = True; not x = False; not y = True.

  37. Q37 · 2 marks

    What is operator precedence? Give an example.

    Answer

    Operator precedence determines the order in which operations are performed in an expression; operators with higher precedence are evaluated before others.

    Example: (3 + 2) * 4 evaluates to 20 because the operation inside parentheses is performed first, while 3 + 2 * 5 gives 13 because multiplication is performed before addition.

  38. Q38 · 2 marks

    Write the order of precedence of the arithmetic operators in Python.

    Answer

    Parentheses () have the highest precedence; then exponentiation (**); then multiplication (*), division (/), and modulus (%); then addition (+) and subtraction (-), which have lower precedence.

  39. Q39 · 2 marks

    Evaluate 4 * 3 + 10 / 2 - 11 % 3 step by step.

    Answer

    4 * 3 evaluates to 12, 10 / 2 evaluates to 5.0 and 11 % 3 evaluates to 2. Then perform addition and subtraction: 12 + 5.0 - 2 = 15.0.

  40. Q40 · 2 marks

    Evaluate (3 + 2) * 5 and 3 + 2 * 5.

    Answer

    (3 + 2) * 5 = 25 because parentheses change the order; 3 + 2 * 5 = 13 because multiplication is performed before addition.

  41. Q41 · 2 marks

    Evaluate 2 ** 3 * 4 and 15 / 3 * 2.

    Answer

    2 ** 3 * 4 = 8 * 4 = 32 (exponentiation before multiplication). 15 / 3 * 2 = 5.0 * 2 = 10.0 (division and multiplication are evaluated left to right).

  42. Q42 · 3 marks

    Evaluate 15 // 4 + 2, 11 // 4 + 2 and 17 % 5 * 2.

    Answer

    15 // 4 + 2 = 3 + 2 = 5; 11 // 4 + 2 = 2 + 2 = 4; 17 % 5 * 2 = 2 * 2 = 4 (modulo is evaluated before multiplication, left to right).

  43. Q43 · 2 marks

    What does it mean that exponentiation is right associative?

    Answer

    When there are multiple operators, Python evaluates them from right to left. For example, 2 3 2 is evaluated as 2 (3 2) = 2 9 = 512.

  44. Q44 · 2 marks

    How does the if statement differ from the if-else statement?

    Answer

    An if statement runs its block of code only when its condition is True; if the condition is False, nothing happens. An if-else statement provides two paths: the if block runs when the condition is True, and the else block runs when the condition is False.

  45. Q45 · 2 marks

    What is the purpose of f before a string in Python?

    Answer

    In Python, f before a string is used for string interpolation, which means embedding variables or expressions inside a string, e.g. print(f'3 + 2 * 5 = {3 + 2 * 5}').

  46. Q46 · 2 marks

    Which operators are evaluated first: multiplication, division and modulus, or addition and subtraction?

    Answer

    Multiplication (*), division (/), and modulus (%) come before addition (+) and subtraction (-), because addition and subtraction have lower precedence.

  47. Q47 · 2 marks

    What is the difference between / and // operators?

    Answer

    The / operator performs division and returns a decimal result (10 / 3 = 3.3333333333333335). The // operator performs floor division and gives the whole-number part (10 // 3 = 3).

Long questions with answers

  1. Q1 · 8 marks

    What are the basic data types in Python? Explain integers, floats, strings, and Booleans with examples.

    Answer

    A variable in Python can store different kinds of data, and the common types are:

    1)Integer (int): stores whole numbers.

    Example: age = 17.

    2)Floating-point (float): stores decimal numbers.

    Example: price = 19.99.

    3)String (str): stores text enclosed in quotation marks.

    Example: name = 'Ali'.

    4)Boolean (bool): stores True or False.

    Example: is_student = True. A variable's value can change during execution (e.g. age = 71 then age = 60).

    Variable naming rules: begin with a letter or underscore, can then contain letters, digits or underscores, are case-sensitive (age and Age differ), and cannot be reserved keywords such as for, while, if.

  2. Q2 · 8 marks

    What are arithmetic operators in Python. Provide examples of each operator and explain when you would use them.

    Answer

    Arithmetic operators perform basic mathematical operations. With a = 10 and b = 3: Addition (+): a + b = 13, used to add values (e.g. totals).

    Subtraction (-): a - b = 7, to find differences. Multiplication (*): a * b = 30, to find products. Division (/): a / b = 3.3333333333333335, returns a decimal result. Floor division (//): a // b = 3, gives the whole-number part of the division. Modulus (%): a % b = 1, gives the remainder (e.g. to check divisibility). Exponentiation (): a b = 1000, raises a number to a power.

    Example code: a = 10; b = 3; print(a, '+', b, '=', a + b).

    Precedence: parentheses first, then **, then *, / and %, then + and -.

  3. Q3 · 8 marks

    Explain the input() and print() functions with examples.

    Answer

    Input and output operations allow you to interact with the user. input(): gets user input; it displays a message on the screen, waits for the user to type something and press Enter, and the entered text is stored in a variable as a string.

    Example: name = input('Enter your name: '). To handle numeric input, convert with int() or float(): user_age = int(input('Enter your age: ')); user_height = float(input('Enter your height in meters: ')). print(): displays information on the screen; it takes one or more arguments and displays them.

    Example: print('Hello, ' + name + '!') gives Hello, Maryam Ashraf! if the user entered Maryam Ashraf; print('Your age is:', user_age) displays the age. Together, input() collects data from the user and print() shows results.

  4. Q4 · 8 marks

    Explain how comparison and logical operators work together in conditional statements. Provide a practical example.

    Answer

    Comparison operators (>, <, ==, !=, >=, <=) compare two values and return True or False. Logical operators (and, or, not) combine multiple conditions: and gives True only if both are True, or gives True if at least one is True, and not reverses a Boolean value. In a conditional statement (if), the condition is built using comparison operators and combined with logical operators; the code block runs only when the whole condition is True.

    Practical example: age = 17; marks = 85; if age >= 16 and marks > 80: print('Eligible for the scholarship') else: print('Not eligible'). Here age >= 16 is True and marks > 80 is True, so True and True gives True and the first message is printed. If the condition were age >= 16 or marks > 90, only one True condition would be needed.

    Note: if and else are standard Python conditional statements not covered in this chapter.

  5. Q5 · 5 marks

    Write a program in Python that will take a name from user and display greeting message to the given name.

    Answer

    Program: name = input('Enter your name: '); print('Hello, ' + name + '!').

    Explanation: input() displays the message, waits for the user to type the name and press Enter, and stores it in the variable name. print() then joins the greeting text, the name and an exclamation mark using +.

    Sample output: Enter your name: Maryam Ashraf then Hello, Maryam Ashraf!. (Write each statement on its own line in the exam.)

  6. Q6 · 5 marks

    Write a program in python that takes two numbers from user and display their sum.

    Answer

    Program: num1 = float(input('Enter first number: ')); num2 = float(input('Enter second number: ')); total = num1 + num2; print('The sum of', num1, 'and', num2, 'is', total).

    Explanation: input() returns a string, so float() (or int() for whole numbers) converts it to a number; the + operator adds the numbers and print() displays the result.

    Sample output: Enter first number: 4 Enter second number: 6 The sum of 4.0 and 6.0 is 10.0.

  7. Q7 · 5 marks

    Write a program in python that five numbers from user and display their average.

    Answer

    Program: n1 = float(input('Enter number 1: ')); n2 = float(input('Enter number 2: ')); n3 = float(input('Enter number 3: ')); n4 = float(input('Enter number 4: ')); n5 = float(input('Enter number 5: ')); average = (n1 + n2 + n3 + n4 + n5) / 5; print('The average is', average).

    Explanation: the five numbers are read with input() and converted with float(); parentheses make the addition happen before division (operator precedence); the sum is divided by 5.

    Sample: entering 2, 4, 6, 8, 10 gives The average is 6.0.

  8. Q8 · 6 marks

    Solve the following expressions: a) 8 + 3 * 4 - 2 ** 2 b) 20 % 7 * 3 + 10 // 3 c) 2 * 3 ** 2 % 4 + 10 - 6 / 2

    Answer

    Precedence: parentheses, then **, then *, / // and % (left to right), then + and -. a) 8 + 3 * 4 - 2 2: 2 2 = 4; 3 * 4 = 12; 8 + 12 - 4 = 16. b) 20 % 7 * 3 + 10 // 3: 20 % 7 = 6; 6 * 3 = 18; 10 // 3 = 3; 18 + 3 = 21. c) 2 * 3 2 % 4 + 10 - 6 / 2: 3 2 = 9; 2 * 9 = 18; 18 % 4 = 2; 6 / 2 = 3.0; 2 + 10 - 3.0 = 9.0.

    Answers: a) 16, b) 21, c) 9.0.

  9. Q9 · 8 marks

    What are the basic data types in Python? Explain integers, floats, strings, and Booleans with examples. (Alternate wording not used; see Test 6 question 1.)

    Answer

    See question 1.

Test yourself on this chapter

Timed chapter tests, marked the moment you finish.

See the chapter tests

Practise with a free account

Save your scores, see which chapters need work, and keep a notebook of every question you got wrong.

Create free account