What is the purpose of comments in a Python program?
Name three primitive data types in Python.
What is operator precedence, and why is it important?
Write a Python program to accept a number from the keyboard and print its square.
Explain the difference between selection and repetition control structures with Python examples.
Answers and Descriptions:
Answer: Comments explain code for readability and future reference.
Description: In Python, single-line comments use #, and multi-line use βββ. They donβt affect execution but help developers understand code logic.Answer: Integer (int), float, string (str).
Description: These are basic data types; int stores whole numbers, float stores decimals, and str stores text, each with specific operations.Answer: Operator precedence determines the order of operations in an expression.
Description: For example, in 3 + 4 * 2, multiplication (*) has higher precedence than addition (+), so the result is 11, not 14. Parentheses can override precedence.Answer:
123num = int(input("Enter a number: "))square = num * numprint("Square is:", square)Description: The program uses input() to get a number, converts it to an integer, calculates its square, and prints the result.
Answer: Selection chooses a path based on a condition (e.g., if); repetition repeats code (e.g., while).
Description: Example: if x > 0: print(βPositiveβ) is selection, executing once if true. while x < 5: x += 1 is repetition, looping until the condition is false.