0% found this document useful (0 votes)
6 views3 pages

Python Programming: Key Questions & Answers

Chapter 2 provides important Python programming questions and answers, including calculating the area of a triangle, average of five numbers, and type conversion. It also explains implicit vs explicit type conversion, Python operators, differences between interactive and script modes, variable naming rules, and the importance of comments. Each section includes code examples for clarity.

Uploaded by

kh6bthmbb6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python Programming: Key Questions & Answers

Chapter 2 provides important Python programming questions and answers, including calculating the area of a triangle, average of five numbers, and type conversion. It also explains implicit vs explicit type conversion, Python operators, differences between interactive and script modes, variable naming rules, and the importance of comments. Each section includes code examples for clarity.

Uploaded by

kh6bthmbb6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chapter 2: Python - Important Questions with Answers

Q1) Write a Python program to:


a) Calculate the area of a triangle with user input
Answer (from book Page 49):
```
Base = int(input("Enter Base: "))
Height = int(input("Enter Height: "))
Area = (Base * Height) / 2
print("Area of Triangle:", Area)
```

b) Calculate the average of 5 numbers entered by the user


Answer (Page 49):
```
English = int(input("English Marks: "))
Maths = int(input("Maths Marks: "))
Science = int(input("Science Marks: "))
SST = int(input("SST Marks: "))
Hindi = int(input("Hindi Marks: "))
Total = English + Maths + Science + SST + Hindi
Average = Total / 5
print("Total Marks:", Total)
print("Average Marks:", Average)
```

c) Take a string and an integer as input and print them together using type conversion
Answer (Page 44-45):
```
Birth_day = 10
Birth_month = "July"
Birth_day = str(Birth_day)
Birth_date = Birth_day + Birth_month
print("Birth Date of the student:", Birth_date)
```

Q2) Difference between implicit and explicit type conversion with examples:
Answer (Page 42–45):
✅ Implicit Conversion:
```
principle_amount = 2000
roi = 4.5
time = 10
simple_interest = (principle_amount * roi * time) / 100
print("Value of Simple Interest:", simple_interest)
```
✅ Explicit Conversion:
```
a = 20
b = "Apples"
print(str(a) + b) # Output: 20Apples
```

Q3) Explain any three Python operators with examples:


Answer (Page 41–42, 47):
1 Arithmetic Operator
1️⃣
```
a = 20
b = 10
print(a + b) # Output: 30
```
2️⃣Comparison Operator
```
print(20 > 10) # Output: True
```
3️⃣Logical Operator
```
print(True and False) # Output: False
```

Q4) Difference between Interactive and Script Mode with examples:


Answer (Page 29–30):
✅ Interactive Mode:
```
>>> 3 + 10
13
>>> print("Hello Learner")
Hello Learner
```
✅ Script Mode:
```
# Save this as [Link]
print("Hello Learner")
Name = "Sam"
print("Learner", Name)
```
Q5) Rules for naming variables/constants with examples:
Answer (Page 38–39):
✅ Correct:
```
total_marks = 100
PI = 3.14
studentName = "Ajay"
```
❌ Incorrect:
```
2value = 50
marks% = 40
total-marks = 100
```

Q6) How are Comments written? Why important? Examples:


Answer (Page 32–33):
```
# This is a single-line comment
a = 10 # Assign value
'''
This is a multi-line comment
Which explains multiple lines.
'''
print(a)
```

You might also like