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

Python Programs for Math Exercises

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

Python Programs for Math Exercises

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

Exercise 1: Prime Numbers Write a Python program that checks whether a given number is

prime or not. A prime number is a natural number greater than 1 that has no positive divisors
other than 1 and itself.

def Prime(n):
for i in range(2,n):
if n%i==0:
result="Not a Prime"
break
else:
result="Prime"
print("Given Number is",result)
x=int(input("Enter Number"))
Prime(x)

Enter Number 23

Given Number is Prime

Exercise 2: Product of Random Numbers Develop a Python program that generates two random
numbers and asks the user to enter the product of these numbers. The program should then
check if the user's answer is correct and display an appropriate message.

from numpy import random


num1=[Link](50)
num2=[Link](60,100)
user_guess=int(input(f"Guess the product of {num1} and {num2}"))
product=num1*num2
if user_guess==product:
print("Your answer is correct")
else:
print("Your answer is wrong")

Guess the product of 3 and 76 34

Your answer is wrong

Exercise 3: Squares of Even/Odd Numbers Create a Python script that prints the squares of all
even or odd numbers within the range of 100 to 200. Choose either even or odd numbers and
document your choice in the code.

oddOrEven=input("Choose either odd or even")


if [Link]()=="odd":
for i in range(100,200):
if i%2!=0:
print(f"{i}^2",i**2)
else:
for i in range(100,200):
if i%2==0:
print(i**i)

Choose either odd or even odd

101^2 10201
103^2 10609
105^2 11025
107^2 11449
109^2 11881
111^2 12321
113^2 12769
115^2 13225
117^2 13689
119^2 14161
121^2 14641
123^2 15129
125^2 15625
127^2 16129
129^2 16641
131^2 17161
133^2 17689
135^2 18225
137^2 18769
139^2 19321
141^2 19881
143^2 20449
145^2 21025
147^2 21609
149^2 22201
151^2 22801
153^2 23409
155^2 24025
157^2 24649
159^2 25281
161^2 25921
163^2 26569
165^2 27225
167^2 27889
169^2 28561
171^2 29241
173^2 29929
175^2 30625
177^2 31329
179^2 32041
181^2 32761
183^2 33489
185^2 34225
187^2 34969
189^2 35721
191^2 36481
193^2 37249
195^2 38025
197^2 38809
199^2 39601

Exercise 4: ✅ Problem Statement (Question): Hospital Billing System A hospital charges its
patients based on the following: • Room charges per day: ₹2,000 • Doctor consultation fee (flat):
₹1,500 • Lab test charges: Based on the number of tests taken. Each test costs ₹300 • Medicine
charges: Total cost of medicines provided • Discount: If the total bill (before discount) exceeds
₹10,000, a 10% discount is applied Write a Python program to calculate the final bill for a
patient who: • Stayed for 4 days • Had 3 lab tests • Had medicine charges of ₹2,400

no_Of_Days=int(input("Enter the number of days patient stayed"))


no_Of_Test=int(input("Enter the number of test patient taken"))
Room_charge=2000* no_Of_Days
Consultation=1500
test=300*no_Of_Test
Medicine=2400
total_bill= Room_charge+ Consultation + test + Medicine
print(total_bill)
if total_bill > 10000:
final_bill = total_bill - ((10/100)*total_bill)

else:
final_bill = total_bill

print("Final Bill is",final_bill)

Enter the number of days patient stayed 4


Enter the number of test patient taken 3

12800
Final Bill is 11520.0

You might also like