Class 8 Python Basics Exercise Solution

 Class 8 Python Basics Exercise Solution


A. Fill in the blanks related to Python Tokens

1. A _______ is a special word in Python that has a specific meaning, like `if`, `for`, or `def`.

2. A _______ is the name you give to a variable, like `age`, `score`, or `name`.

3. The _______ symbol is used to give a value to a variable, like `x = 10`.

4. The _______ symbol is used to check if two things are the same, like `x == 5`.

5. A _______ is a value like a number (`10`), a word (`'hello'`), or `True/False`.

6. The _______ symbol is used to check if one value is greater than another (e.g., `if x > 10`).

7. The _______ function is used to display text on the screen, like `print('Hello World!')`.

8. A _______ is a symbol that does something with numbers, like `+` (addition), `-` (subtraction), or `` (multiplication).

9. The _______ symbol is used to combine two strings together (e.g., `'Hello' + ' ' + 'World'`).

10. The _______ symbol is used to add two numbers together, like `a + b`.

11. A _______ symbol is used to perform division between two numbers (e.g., `x / y`).

12. The _______ operator checks if two values are not equal to each other (e.g., `if x != 5`).

13. The _______ function is used to convert a value into an integer, like `int('7')` which gives `7`.

14. A _______ is a sequence of characters enclosed in quotes, like `'Python'`.

15. The _______ operator is used to find the remainder after division (e.g., `5 % 2` results in `1`).


Answers:

1. Keyword

2. Identifier

3. Assignment

4. Equality

5. Literal

6. > (Greater than)

7. print

8. Operator

9. + (Concatenation)

10. + (Addition)

11. / (Division)

12. != (Not equal)

13. int

14. String

15. % (Modulus)


B. MCQ Question Answer.

 1. Who is the creator of Python?

   a) Bill Gates  

   b) James Gosling  

   c) Guido van Rossum  

   d) Dennis Ritchie  

   Answer: c) Guido van Rossum

 2. In what year was Python first released?

   a) 1991  

   b) 1989  

   c) 2000  

   d) 1995  

   Answer: a) 1991

 3. Which Python mode allows you to type code directly and see the result immediately?

   a) Script mode  

   b) Interactive mode  

   c) Command-line mode  

   d) Editor mode  

   Answer: b) Interactive mode

 4. Which of the following is used to write Python programs in script mode?

   a) Python shell  

   b) Python file (.py)  

   c) Python notebook  

   d) Python interpreter  

   Answer: b) Python file (.py)

 5. Which of the following types of data can be stored in a string variable in Python?

   a) Integer  

   b) Boolean  

   c) Characters  

   d) List  

   Answer: c) Characters

 6. Which function is used to print output in Python?

   a) show()  

   b) print()  

   c) output()  

   d) display()  

   Answer: b) print()

 7. What will be the output of the following Python code: `print("Hello" + " " + "World")`?

   a) HelloWorld  

   b) "Hello World"  

   c) Hello World  

   d) SyntaxError  

   Answer: c) Hello World

 8. Which function is used to take input from the user in Python?

   a) input()  

   b) scan()  

   c) get()  

   d) read()  

   Answer: a) input()

 9. What is the data type of the value returned by `input()` in Python?

   a) int  

   b) string  

   c) float  

   d) bool  

   Answer: b) string

 10. What will be the output of the following Python code: `int("5") + int("7")`?

   a) 12.0  

   b) "57"  

   c) 12  

   d) Error  

   Answer: c) 12

 11. Which of the following Python data types is used to store numbers with decimal points?

   a) int  

   b) float  

   c) string  

   d) complex  

   Answer: b) float

 12. In Python, the symbol + is used for which of the following?

    a) Addition of two numbers

    b) String concatenation

    c) Both a and b

    d) None of the above

    Answer: c) Both a and b

 13. Which of the following is an example of a valid string in Python?

   a) 'Hello'  

   b) "Python"  

   c) '''Multiline string'''  

   d) All of the above  

   Answer: d) All of the above

 14. Which of the following is used to convert a string containing a number into an integer in Python?

   a) int()  

   b) float()  

   c) eval()  

   d) str()  

   Answer: a) int()

 15. What will be the output of the following code: `print("5" * 3)`?

   a) 555  

   b) 15  

   c) Error  

   d) "5 5 5"  

   Answer: a) 555

 16. What is the data type of the result when you divide two integers in Python?

    a) int

    b) float

    c) complex

    d) None of the above

    Answer: b) float

 17. What is the purpose of the `eval()` function in Python?

   a) To evaluate mathematical expressions  

   b) To execute Python code dynamically  

   c) To convert strings to integers  

   d) Both a and b  

   Answer: d) Both a and b

 18. Which of the following is used to convert a string to a float in Python?

   a) float()  

   b) str()  

   c) eval()  

   d) int()  

   Answer: a) float()

 19. What is the default data type for numbers in Python?

   a) int  

   b) float  

   c) complex  

   d) None of the above  

   Answer: b) float

 20. Which of the following is the correct way to create a string variable in Python?

   a) string = "Hello"  

   b) string = Hello  

   c) string = 'Hello'  

   d) Both a and c  

   Answer: d) Both a and c