Chapter 3_ Charming the Python
Chapter 3_ Charming the Python
MCQ
```python
Print(“The total number of geals scored by captain sunil Chhetri 14, 235)
```
Has a **syntax error** (missing closing quotation mark). Assuming the intended statement
was:
```python
Print(“The total number of goals scored by captain Sunil Chhetri is”, 235)
```
```
```
#### **Answer:** **(b) The total number of goals scored by captain Sunil Chhetri is 235**
```python
```
Here, `”marks”` is treated as a string, **not a variable**. The correct way to use the
variable is:
```python
```
```
```
Given table:
|--------------------|----------------------|
Code:
```python
```
```python
```
This would output `93`, but **with the given incorrect code**, the output will be:
```
```
DESCRIPTIVE QUESTIONS:
1. Write the output of the following programs:
a.
Print("Python is fun")
print("Python is fun")
Output:
Python is fun
b.
Print("5+3")
5+3
c.
Print("5,3")
5,3
d.
Print("5/n3")
5
3
Since Print is incorrect (it should be print), this will cause an error.
If corrected, the output will be:
Explanation:
3. Program to take inputs for boys, girls, and teachers, then display total students and
teacher-student ratio
# Taking inputs
boys = int(input("Enter the number of boys: "))
girls = int(input("Enter the number of girls: "))
teachers = int(input("Enter the number of teachers: "))
# Displaying results
print("Total number of students:", total_students)
print("Number of teachers per student:", teachers_per_student)
4. Explanation of operators:
a. == (Equality Operator)
• Divides two numbers and returns the integer quotient, discarding the decimal part.
• Example:
• print(10 // 3) # Output: 3
• print(7 // 2) # Output: 3
c. % (Modulo Operator)
5. Programs to explain:
a. String Concatenation
str1 = "Hello"
str2 = "World"
result = str1 + " " + str2
print(result)
Output:
Hello World
b. Type Casting
num_str = "123"
num_int = int(num_str) # Converts string to integer
num_float = float(num_str) # Converts string to float