0% found this document useful (0 votes)
11 views21 pages

Ip Practical File

The document is a practical file for Informatics Practices (Code-065) submitted by Inderjot Singh. It contains a list of programming assignments (WAPs) that involve various tasks such as checking divisibility, performing mathematical operations, calculating grades, and finding areas of shapes using Python. Each assignment includes a brief description, code snippets, and expected outputs.

Uploaded by

mysterygill77
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)
11 views21 pages

Ip Practical File

The document is a practical file for Informatics Practices (Code-065) submitted by Inderjot Singh. It contains a list of programming assignments (WAPs) that involve various tasks such as checking divisibility, performing mathematical operations, calculating grades, and finding areas of shapes using Python. Each assignment includes a brief description, code snippets, and expected outputs.

Uploaded by

mysterygill77
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/ 21

INFORMATICS PRACTICES

PRACTICAL FILE
CODE-065

Submitted to- Mr. Ravi Anand Submitted by- Inderjot Singh


2

S.no NAME Pg No.


1 WAP to accept two numbers and check
for their divisibility i.e. if the first number
is completely divisible by the second. The
5
program should be able to handle divide
by zero error i.e. the program should carry
out divisibility only if the denominator is
non-zero

2 WAP to accept two numbers and a


mathematical operator and carry out the
calculation as per the given operator. For
5-6
example if the given operator is ‘+’, then
the program should find the sum of the
two numbers. Check for all 7 Python
mathematical operators

3 WAP to accept the firstname, lastname


and gender of a user and display the
following message “Hello, Mr./Ms
6-7
Firstname Lastname Welcome!! Hope You
like this program”

4 WAP to accept marks of a student in 5


subjects and calculate the total marks,
percentage, grade and result of the
7-8
student. The grade is assigned as per the
following scheme: GRADING SCALE
GRADE UPPER LIMIT LOWER LIMIT A1
100.00 90.00 A2 89.99 80.00 B1 79.99 70.00
B2 69.99 60.00 C1 59.99 50.00 C2 49.99
40.00 D 39.99 33.00 E 32.99 0.00 The result
is displayed as “PASS” %age is more than
33% and “FAIL” otherwise.

5 WAP to extract the last digit of any


number entered by the user and check
whether the digit is divisible by 3
8-9

6 WAP to provide the user choice of finding


the area of closed figures (square,
rectangle, circle, triangle). Display a menu
9-10
to the user for accepting input for the
choice of the figure and take input,
3

7 WAP to accept an alphabet and check


whether it is a vowel or not. 10
8 WAP to accept the customer type and bill
amount and calculate the discount and
net amount to be paid. The discount is
11
given according to customer type.
Customer type Discount Platinum 20%
Gold 10% Silver 5% Neither 0%

9 WAP to accept the purchase amount and


calculate the Discount as well as the net
amount to be
11-12
paid

10 WAP to accept three numbers and find


the largest of them. 12-13
11 WAP to accept the three sides of a
triangle and find if given triangle
dimensions make a Pythagoras triangle.
13
12 WAP to accept the three dimensions of a
triangle and find if with given triangle
dimensions, the triangle formation is
13-14
possible or not.

13 WAP to accept a number and display its


multiplication table up till the given last
number.
14-15
14 Write a menu driven program that gives
the choice to the user to find the sum of
any of the
15
following series:
(i) 1+2+3+....... +N
(ii) 1+3+5+....... +N

15 WAP to compute the sum of the following


series:
2
16
2+42+62+....... +N2

16 WAP to accept the starting no., ending


no., difference in terms of series, and
display the
16-17
series as well as the sum of the series.

17 WAP to find factors of a given number


and also find if the given no. is a perfect
no. A perfect no’s sum of factors excluding
17
4

itself is equal to the number e.g. 6 (factors


1+2+3 = 6 which is the same as 6).

18 WAP to accept the base and exponent


and find the power. 18
19 WAP to accept a number and find its
factorial. 18-19
20 WAP to find the sum of the following
series:
1/1 + 1/2 + 1/3 + 1/4 + ............... 1/N
19
21 WAP to accept the beginning number,
ending number, and difference in the
terms of the series and display the terms
19-20
of the series.

22 WAP to accept a string and find the


number of lowercase alphabets,
uppercase alphabets, digits, blank spaces,
20-11
and special characters in it separately.
5

1. WAP to accept two numbers and check for their divisibility


i.e. if the first number is completely divisible by the second.
The program should be able to handle divide by zero error i.e.
the program should carry out divisibility only if the
denominator is non-zero.

num1 = int(input("Enter the first number: "))


num2 = int(input("Enter the second number: "))
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
if num1 % num2 == 0:
print(f"{num1} is completely divisible by {num2}.")
else:
print(f"{num1} is not completely divisible by {num2}.")

Output:

Enter the first number: 4


Enter the second number: 2
4 is completely divisible by 2.

2. WAP to accept two numbers and a mathematical operator


and carry out the calculation as per the given operator. For
example if the given operator is ‘+’, then the program should
find the sum of the two numbers. Check for all 7 Python
mathematical operators.

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
operator = input("Enter the operator (+, -, *, /, %, **, //): ")

if operator == '+':
print(f"The result is {num1 + num2}")
elif operator == '-':
print(f"The result is {num1 - num2}")
6

elif operator == '*':


print(f"The result is {num1 * num2}")
elif operator == '/':
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
print(f"The result is {num1 / num2}")
elif operator == '%':
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
print(f"The result is {num1 % num2}")
elif operator == '**':
print(f"The result is {num1 ** num2}")
elif operator == '//':
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
print(f"The result is {num1 // num2}")
else:
print("Invalid operator.")

Output:

Enter the first number: 5


Enter the second number: 2
Enter the operator (+, -, *, /, %, **, //): +
The result is 7.0

3. WAP to accept the firstname, lastname and gender of a user


and display the following message “Hello, Mr./Ms Firstname
Lastname Welcome!! Hope You like this program”

firstname = input("Enter your first name: ")


lastname = input("Enter your last name: ")
gender = input("Enter your gender (M/F): ")
7

if gender.upper() == 'M':
title = "Mr."
else:
title = "Ms."
print(f"Hello, {title} {firstname} {lastname} Welcome!! Hope You
like this program")

Output:

Enter your first name: Gurjais


Enter your last name: kalra
Enter your gender (M/F): M
Hello, Mr. Gurjais Kalra Welcome!! Hope You like this program

4. WAP to accept marks of a student in 5 subjects and calculate


the total marks, percentage, grade and result of the student.
The grade is assigned as per the following scheme: GRADING
SCALE GRADE UPPER LIMIT LOWER LIMIT A1 100.00 90.00 A2
89.99 80.00 B1 79.99 70.00 B2 69.99 60.00 C1 59.99 50.00 C2
49.99 40.00 D 39.99 33.00 E 32.99 0.00 The result is displayed
as “PASS” %age is more than 33% and “FAIL” otherwise.

marks = [float(input(f"Enter marks for subject {i+1}: ")) for i in


range(5)]

total_marks = sum(marks)
percentage = (total_marks / 500) * 100

if percentage >= 90:


grade = "A1"
elif percentage >= 80:
grade = "A2"
elif percentage >= 70:
grade = "B1"
elif percentage >= 60:
8

grade = "B2"
elif percentage >= 50:
grade = "C1"
elif percentage >= 40:
grade = "C2"
elif percentage >= 33:
grade = "D"
else:
grade = "E"

result = "PASS" if percentage > 33 else "FAIL"

print(f"Total Marks: {total_marks}")


print(f"Percentage: {percentage:.2f}%")
print(f"Grade: {grade}")
print(f"Result: {result}")

Output:

Enter marks for subject 1: 50


Enter marks for subject 2: 60
Enter marks for subject 3: 70
Enter marks for subject 4: 50
Enter marks for subject 5: 40
Total Marks: 270.0
Percentage: 54.00%
Grade: C1
Result: PASS

5. WAP to extract the last digit of any number entered by the


user and check whether the digit is divisible by 3

number = int(input("Enter a number: "))


last_digit = (number) % 10
if last_digit % 3 == 0:
print(f"The last digit {last_digit} is divisible by 3.")
9

else:
print(f"The last digit {last_digit} is not divisible by 3.")

Output:

Enter a number: 19
The last digit 9 is divisible by 3.

6. WAP to provide the user choice of finding the area of closed


figures (square, rectangle, circle, triangle). Display a menu to
the user for accepting input for the choice of the figure and
take input, calculate, and display the area of the figure
chosen by the user accordingly.

print("Choose a figure to calculate area:")


print("1. Square")
print("2. Rectangle")
print("3. Circle")
print("4. Triangle")
choice = int(input("Enter your choice (1-4): "))
if choice == 1:
side = float(input("Enter the side length of the square: "))
area = side ** 2
print(f"Area of the square: {area}")
elif choice == 2:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = length * width
print(f"Area of the rectangle: {area}")
elif choice == 3:
radius = float(input("Enter the radius of the circle: "))
area = 3.14159 * radius ** 2
print(f"Area of the circle: {area}")
elif choice == 4:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
10

area = 0.5 * base * height


print(f"Area of the triangle: {area}")
else:
print("Invalid choice.")

Output:

Choose a figure to calculate area:


1. Square
2. Rectangle
3. Circle
4. Triangle
Enter your choice (1-4): 1
Enter the side length of the square: 2
Area of the square: 4.0

7. WAP to accept an alphabet and check whether it is a vowel


or not.

alphabet = input("Enter an alphabet: ").lower()


if alphabet in 'aeiou':
print(f"{alphabet} is a vowel.")
else:
print(f"{alphabet} is not a vowel.")

Output:

Enter an alphabet: l
l is not a vowel.

8. WAP to accept the customer type and bill amount and


calculate the discount and net amount to be paid. The
11

discount is given according to customer type. Customer type


Discount Platinum 20% Gold 10% Silver 5% Neither 0%

customer_type = input("Enter customer type


(Platinum/Gold/Silver/Neither): ").lower()
bill_amount = float(input("Enter the bill amount: "))
if customer_type == 'platinum':
discount = 0.20
elif customer_type == 'gold':
discount = 0.10
elif customer_type == 'silver':
discount = 0.05
else:
discount = 0.00
discount_amount = bill_amount * discount
net_amount = bill_amount - discount_amount

print(f"Discount: {discount * 100}%")


print(f"Discount Amount: {discount_amount:}")
print(f"Net Amount to be Paid: {net_amount:}")

Output:

Enter customer type (Platinum/Gold/Silver/Neither): gold


Enter the bill amount: 7000
Discount: 10.0%
Discount Amount: 700.0
Net Amount to be Paid: 6300.0

9. An electronic shop has announced the following seasonal


discounts Purchase Amount Discount 25000 - 50000 10%
50001-100000 15% 100001-150000 20% Above 150001 25% WAP
to accept the purchase amount and calculate the Discount as
well as the net amount to be paid
12

purchase_amount = float(input("Enter the purchase amount: "))


if 25000 <= purchase_amount <= 50000:
discount = 0.10
elif 50001 <= purchase_amount <= 100000:
discount = 0.15
elif 100001 <= purchase_amount <= 150000:
discount = 0.20
elif purchase_amount > 150000:
discount = 0.25
else:
discount = 0.00
discount_amount = purchase_amount * discount
net_amount = purchase_amount - discount_amount

print(f"Discount: {discount * 100}%")


print(f"Discount Amount: {discount_amount:}")
print(f"Net Amount to be Paid: {net_amount:}")

Output:

Enter the purchase amount: 60000


Discount: 15.0%
Discount Amount: 9000.0
Net Amount to be Paid: 51000.0

10. WAP to accept three numbers and find the largest of them.

a = float(input("Enter the first number: "))


b = float(input("Enter the second number: "))
c = float(input("Enter the third number: "))
largest = max(a, b, c)
print(f"The largest number is {largest}")
13

Output:

Enter the first number: 10


Enter the second number: 20
Enter the third number: 340
The largest number is 340.0

11. WAP to accept the three sides of a triangle and find if given
triangle dimensions make a Pythagoras triangle.

a = float(input("Enter the first side: "))


b = float(input("Enter the second side: "))
c = float(input("Enter the third side: "))
if (a**2 + b**2 == c**2) or (a**2 + c**2 == b**2) or (b**2 + c**2 == a**2):
print("The triangle is a Pythagorean triangle.")
else:
print("The triangle is not a Pythagorean triangle.")

Output:

Enter the first side: 3


Enter the second side: 4
Enter the third side: 5
The triangle is a Pythagorean triangle.

12. WAP to accept the three dimensions of a triangle and find if


with given triangle dimensions, the triangle formation is
possible or not. ITERATIVE STATEMENT – LOOPS (NUMERICAL
PROBLEMS) (USING WHILE LOOP)
14

a = float(input("Enter the first side: "))


b = float(input("Enter the second side: "))
c = float(input("Enter the third side: "))
if a + b > c and a + c > b and b + c > a:
print("The triangle can be formed.")
else:
print("The triangle cannot be formed.")

Output:

Enter the first side: 3


Enter the second side: 4
Enter the third side: 5
The triangle can be formed.

13. WAP to accept a number and display its multiplication table


up till the given last number.

num = int(input("Enter a number: "))


last_num = int(input("Enter the last number: "))
i=1
while i <= last_num:
print(f"{num} x {i} = {num * i}")
i += 1

Output:

Enter a number: 10
Enter the last number: 2
10 x 1 = 10
10 x 2 = 20

14. Write a menu driven program that gives the choice to the
user to find the sum of any of the following series: (i)
1+2+3+....... +N (ii) 1+3+5+....... +N
15

print("Choose a series to find the sum:")


print("1. 1 + 2 + 3 + ... + N")
print("2. 1 + 3 + 5 + ... + N")
choice = int(input("Enter your choice (1 or 2): "))
if choice == 1:
N = int(input("Enter the value of N: "))
sum_series = 0
i=1
while i <= N:
sum_series += i
i += 1
print(f"Sum of series 1 + 2 + 3 + ... + {N} is {sum_series}")
elif choice == 2:
N = int(input("Enter the value of N (last odd number): "))
sum_series = 0
i=1
while i <= N:
sum_series += i
i += 2
print(f"Sum of series 1 + 3 + 5 + ... + {N} is {sum_series}")
else:
print("Invalid choice.")

Output:

Choose a series to find the sum:


1. 1 + 2 + 3 + ... + N
2. 1 + 3 + 5 + ... + N
Enter your choice (1 or 2): 2
Enter the value of N (last odd number): 35
Sum of series 1 + 3 + 5 + ... + 35 is 324

15. WAP to compute the sum of the following series: 2^2 + 4^2 +
6^2 + ....... +N^2
16

N = int(input("Enter the value of N: "))


sum_series = 0
i=2
while i <= N:
sum_series += i ** 2
i += 2
print(f"Sum of the series 2^2 + 4^2 + 6^2 + ... + {N}^2 is
{sum_series}")

Output:

Enter the value of N: 5


Sum of the series 2^2 + 4^2 + 6^2 + ... + 5^2 is 20

16. WAP to accept the starting no., ending no., difference in terms of
series, and display the series as well as the sum of the series.

start = int(input("Enter the starting number: "))


end = int(input("Enter the ending number: "))
difference = int(input("Enter the difference: "))
current = start
series_sum = 0
for x in range(start,end+1,difference):
print(x)
series_sum += x
print(f"\nSum of the series: {series_sum}")

Output:

Enter the starting number: 2


Enter the ending number: 10
Enter the difference: 2
2
4
17

6
8
10

Sum of the series: 30

17. WAP to find factors of a given number and also find if the given
no. is a perfect no. A perfect no’s sum of factors excluding itself is
equal to the number e.g. 6 (factors 1+2+3 = 6 which is the same as
6).

num = int(input("Enter a number: "))


sum_factors = 0
for i in range(1, num // 2 + 1):
if num % i == 0:
sum_factors += i
if sum_factors == num:
print(f"{num} is a perfect number.")
else:
print(f"{num} is not a perfect number.")

Output:

Enter a number: 10
10 is not a perfect number.

18. WAP to accept the base and exponent and find the power.

base = float(input("Enter the base: "))


exponent = int(input("Enter the exponent: "))
result = 1
i=0
while i < exponent:
result *= base
18

i += 1
print(f"{base} ^ {exponent} = {result}")

Output:

Enter the base: 10


Enter the exponent: 2
10.0 ^ 2 = 100.0

19. WAP to accept a number and find its factorial. ITERATIVE


STATEMENT – LOOPS (NUMERICAL PROBLEMS) (USING FOR LOOP)

num = int(input("Enter a number: "))


factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print(f"Factorial of {num} is {factorial}")

Output:

Enter a number: 9
Factorial of 9 is 362880

20. WAP to find the sum of the following series: 1/1 + 1/2 + 1/3 +
1/4 + ............... 1/N

N = int(input("Enter the value of N: "))


sum_series = 0.0
i=1
while i <= N:
19

sum_series += 1 / i
i += 1
print(f"Sum of the series 1/1 + 1/2 + 1/3 + ... + 1/{N} is {sum_series:}")

Output:

Enter the value of N: 10


Sum of the series 1/1 + 1/2 + 1/3 + ... + 1/10 is 2.9289682539682538

21. WAP to accept the beginning number, ending number, and


difference in the terms of the series and display the terms of the
series. SEQUENCES – STRINGS (USING FOR LOOP)

start = int(input("Enter the beginning number: "))


end = int(input("Enter the ending number: "))
difference = int(input("Enter the difference: "))
for x in range(start,end+1,difference):
print(x)

Output:

Enter the beginning number: 10


Enter the ending number: 20
Enter the difference: 1
10
11
12
13
14
15
16
17
18
19
20
20

22. WAP to accept a string and find the number of


lowercase alphabets, uppercase alphabets, digits, blank
spaces, and special characters in it separately.

string = input("Enter a string: ")


lowercase_count = 0
uppercase_count = 0
digit_count = 0
space_count = 0
special_count = 0
for char in string:
if char.islower():
lowercase_count += 1
elif char.isupper():
uppercase_count += 1
elif char.isdigit():
digit_count += 1
elif char.isspace():
space_count += 1
else:
special_count += 1
print(f"Lowercase letters: {lowercase_count}")
print(f"Uppercase letters: {uppercase_count}")
print(f"Digits: {digit_count}")
print(f"Blank spaces: {space_count}")
print(f"Special characters: {special_count}")

Output:

Enter a string: Hello everyone


Lowercase letters: 12
Uppercase letters: 1
Digits: 0
Blank spaces: 1
Special characters: 0
21

Thank you

You might also like