0% found this document useful (0 votes)
2 views2 pages

Chapter 3

Chapter 3 provides a series of Python programming exercises that include calculating the discriminant of a quadratic equation, finding the average temperature over a year, reversing a three-digit number, formatting a customer's name, and calculating simple and compound interest. Each exercise includes sample code and prompts for user input. The chapter aims to enhance programming skills through practical applications.
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)
2 views2 pages

Chapter 3

Chapter 3 provides a series of Python programming exercises that include calculating the discriminant of a quadratic equation, finding the average temperature over a year, reversing a three-digit number, formatting a customer's name, and calculating simple and compound interest. Each exercise includes sample code and prompts for user input. The chapter aims to enhance programming skills through practical applications.
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
You are on page 1/ 2

Chapter 3 – Introduction to Python

Programming Questions
1 Write a Python program to get the values for a, b, c and evaluate the following
expression
delta=√ b2−4 ac
import math

a = float(input("Enter a: "))
b = float(input("Enter b: "))
c = float(input("Enter c: "))

delta = math.sqrt(b ** 2 - 4 * a * c)

print("Delta is ", delta)


2 Find out the temperature for 12 months of the year and find out the year’s average
temperature.
# create an empty list to store temperatures
temperatures = []

# use a for loop to get temperatures for each month


for i in range(1, 13):
temp = float(input("Enter temperature for month {}: ".format(i)))
temperatures.append(temp)

# calculate the average temperature


average_temp = sum(temperatures) / len(temperatures)

# print the average temperature


print("The average temperature for the year is: {:.2f}
degrees".format(average_temp))
3 Take a three-digit number and find the reverse of the number.
num = int(input("Enter a three-digit number: "))

digit1 = num % 10
digit2 = (num // 10) % 10
digit3 = num // 100
reverse_num = digit1 * 100 + digit2 * 10 + digit3

print("The reverse of the number is:", reverse_num)


4 Take the customer’s first name and last name and print them as last name first
followed by the first name
first_name = input("Enter customer's first name: ")
last_name = input("Enter customer's last name: ")

print("Customer name:", last_name + ", " + first_name)


5 Get the principal amount, interest, and year and find the simple interest and
compound interest.
p = float(input("Enter principal amount: "))
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
r = float(input("Enter interest rate (In percentage): "))
n = int(input("Enter number of years(In years): "))

# calculate simple interest


simple_interest = (p * n * r) / 100

# calculate compound interest


compound_interest = p * ((1 + (r / 100)) ** n - 1)

# print the simple interest and compound interest


print("Simple interest:", simple_interest)
print("Compound interest:", compound_interest)

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD

You might also like