Sunday, 2 July 2023

Python Programming Chapter 1 - Basic Questions

 

 

PYTHON PROGRAMS

 

1.1.  Write a program to show a message only.

 

print("Technologica \nComputer \nEducation \nSociety");

 

Output:

 

Technologica

Computer

Education

Society

 

 

1.2 Write a program to addition of two numbers

 

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

c=a+b;

print("Addition : ",c);

 

Output:

 

Enter the 1st number :  20

Enter the 2ndnumber :  30

 

Addition : 50

 

1.3 Write a program to calculation of two numbers

 

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

Add=a+b;

Sub=a-b;

Mult=a*b;

Div=a/b;

print("Addition : ",Add);

print("Subtraction : ",Sub);

print("Multiplication : ",Mult);

print("Division : ",Div);

Output:

 

Enter the 1st number: 20

Enter the 2nd  number: 5

 

Addition: 25

Subtraction: 15

Multiplication: 100

Division: 4

 

 

1.4 Write a program to add three numbers.

 

x=int(input("Enter 1st number : "));

y=int(input("Enter 2nd number : "));

z=int(input("Enter 3rd number : "));

c=x+y+z;

print("Addition : ",c);

 

Output:

 

Enter the 1st Number=           10

Enter the 2nd Number=          20

Enter the 3rd Number=          30

 

Addition = 60

           

 

1.5 Write a program to calculate the area and circumference of a circle.

 

radius=int(input("Enter Radius (cm) : "));

Area=(22/7)*radius*radius;

Circumference=2*(22/7)*radius;

print("Area of Circle(sqcm) = ",Area);

print("Circumference of Circle(cm) = ",Circumference);

 

Output:

 

Enter Radius (cm) : 20

Area of Circle(sqcm) =  1257.14285714

Circumference of Circle(cm) =  125.714285714

1.6 Write a program to calculate the area and perimeter of a rectangle.

 

length=int(input("Enter Length(cm) : "));

width=int(input("Enter Width(cm) : "));

Area=length*width;

Perimeter=2*(length+width);

print("Area of Rectangle(sqcm) = ",Area);

print("Perimeter of Rectangle(cm)= ",Perimeter);

 

Output:

 

Enter Length(cm) : 20

Enter Width(cm) : 10

Area of Rectangle(sqcm) =  200

Perimeter of Rectangle(cm)=  60

 

1.7 Write a program to calculate the distance covered by a wheel in Kilometer if the radius in centimeter is given through the keyboard.

 

radius=int(input("Enter Radius (cm) : "));

rotation=int(input("Enter Rotation : "));

circumference=2*(22/7)*radius;

distance=(circumference*rotation)/100000;

print("Circumference of Circle(cm) = ",circumference);

print("Distance Covered(km) = ",distance);

 

Output:

 

Enter Radius (cm) : 20

Enter Rotation : 1000

Circumference of Circle(cm) =  125.714285714

Distance Covered(km) =  1.25714285714

1.8 Write a program to calculate total cost for coloring a room if height, width, length and color rate is given through the keyboard.

 

length=int(input("Enter Length(feet) : "));

width=int(input("Enter Width(feet) : "));

height=int(input("Enter Height(feet) : "));

rs=int(input("Enter the Rate for the Coloring as Per Square feet Rs. : "))

TotalArea=(2*(length*height))+(2*(width*height))+(length*width);

TotalCost=TotalArea*rs;

print("Total Area (sqft)= ",TotalArea);

print("Total Cost(Rs.)= ",TotalCost);

 

Output:

 

Enter Length(feet) : 16

Enter Width(feet) : 12

Enter Height(feet) : 20

Enter the Rate for the Coloring as Per Square feet Rs. : 20

Total Area (sqft)=  1312

Total Cost(Rs.)=  26240

1.9 Write a program to calculate the distance in Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter, Inch, Feet and Gauge if it is entered as in Kilometer.

 

km=int(input("Enter the distance in Kilometer (KM) : "))

hm=km*10;

dcm=hm*10;

m=dcm*10;

dm=m*10;

cm=dm*10;

mm=cm*10;

inch=cm/2.54;

ft=inch/12;

g=ft/3;

print(" Distance in Kilometer = ",km);

print(" Distance in Hectometer  = ",hm);

print(" Distance in Decameter = ",dcm);

print(" Distance in Meter = ",m);

print(" Distance in Decimeter = ",dm);

print(" Distance in Centimeter = ",cm);

print(" Distance in Millimeter = ",mm);

print(" Distance in inch = ",inch);

print(" Distance in Feet = ",ft);

print(" Distance in Gouge = ",g);

 

Output:

Enter the distance in Kilometer (KM) : 10

 Distance in Kilometer =  10

 Distance in Hectometer  =  100

 Distance in Decameter =  1000

 Distance in Meter =  10000

 Distance in Decimeter =  100000

 Distance in Centimeter =  1000000

 Distance in Millimeter =  10000000

 Distance in inch =  393700.787402

 Distance in Feet =  32808.3989501

 Distance in Gouge =  10936.1329834

 

1.10 Write a program to calculate the retail price for a product if the name and rate and quantity are given through the keyboard.

 

pn=input(" Enter The Product Name : ")

r=int(input(" Enter The Rate Rs. : "))

qty=int(input(" Enter the Quantity (pcs) : "))

t= r*qty;

cc=t*.1;

vat=t*.05;

p=t*.35;

rp=t+cc+vat+p;

print("\n Retail Price (Rs.)= ",rp);

 

Output:

 

Enter The Product Name : lux

 Enter The Rate Rs. : 10

 Enter the Quantity (pcs) : 20

 

 Retail Price (Rs.)=  300.0

1.11 Write a program to calculate estimated population on a certain period.

 

p=int(input(" Enter The Current Population Of The Area : "))

r=float(input(" Enter The Current Population Of The Rate : "))

t=int(input(" Enter The Current Population Of The Time : "))

a=1+r/100;

b=pow(a,t);

ci= p*b;

print("The Estimated Population= ",ci);

 

 

 

 

Output:

 

Enter The Current Population Of The Area : 1000

 Enter The Current Population Of The Rate : 1.2

 Enter The Current Population Of The Time : 3

The Estimated Population=  1036.433728

1.12 Write a program to calculate the discount on a product.

 

pn=input(" Enter The Product Name : ")

p=float(input(" Enter the Price in Rs. : "))

dis=float(input(" Enter the Discount Percentage(%) : "))

rp=p-(p*dis/100);

print("The Current Price In Rs. = ",rp);

 

 

Output:

 

Enter The Product Name : lux

 Enter the Price in Rs. : 1000

 Enter the Discount Percentage(%) : 10

The Current Price In Rs. =  900.0

1.13 Write a program to calculate the simple interest and final amount  if principal, interest rate and time in years are given through the keyboard.

 

p=float(input("Enter the Principal Amount Rs. : "))

r=float(input("Enter the Rate(%) : "))

t=float(input("Enter The Time In Years : "))

si=p*r*t/100;

amt=si+p;

print("The Simple Interest = Rs.",si);

print("The Final Amount = Rs.",amt);

 

 

Output:

 

Enter the Principal Amount Rs. : 1000

Enter the Rate(%) : 10

Enter The Time In Years : 5

The Simple Interest = Rs. 500.0

The Final Amount = Rs. 1500.0

1.14 Write a program to calculate the simple interest and final amount with installment facilities  if principal, interest rate and time in years are given through the keyboard.

 

p=float(input("Enter the Principal Amount Rs. : "))

r=float(input("Enter the Rate(%) : "))

t=float(input("Enter The Time In Years : "))

si=p*r*t/100;

amt=si+p;

y=amt/t;

m=y/12;

d=y/365.25;

print("The Simple Interest = Rs.",si);

print("The Final Amount = Rs.",amt);

print("The Yearly Installment = Rs.",y);

print("The Monthly Installment = Rs.",m);

print("The Daily Installment = Rs.",d);

 

Output:

 

Enter the Principal Amount Rs. : 1000

Enter the Rate(%) : 10

Enter The Time In Years : 5

The Simple Interest = Rs. 500.0

The Final Amount = Rs. 1500.0

The Yearly Installment = Rs. 300.0

The Monthly Installment = Rs. 25.0

The Daily Installment = Rs. 0.82135523614

1.15 Write a program if input is 1 then output is 0 if input is 0 output is 1

                       

a=int(input("Enter The No : "))

b=1-a;

print("Result = ",b);

 

Output:

 

Enter The No : 1

Result =  0

1.16 Write a program to create a salary sheet

basic=int(input("Enter the basic salary: Rs."))

da=basic*0.45;

ta=basic*0.30;

hra=basic*0.20;

it=basic*0.04;

pf=basic*0.08;

gp=basic+da+ta+hra;

np=gp-it-pf;

 

print("Basic salary is: Rs.",basic);

print("D.A. is: Rs.",da);

print("T.A. is: Rs.",ta);

print("H.R..A. is: Rs.",hra);

print("I.T. is: Rs.",it);

print("P.F. is: Rs.",pf);

print("G.P. is: Rs.",gp);

print("N.P. is: Rs.",np);

 

Output

 

Enter the basic salary: Rs.1000

Basic salary is: Rs. 1000

D.A. is: Rs. 450.0

T.A. is: Rs. 300.0

H.R..A. is: Rs. 200.0

I.T. is: Rs. 40.0

P.F. is: Rs. 80.0

G.P. is: Rs. 1950.0

N.P. is: Rs. 1830.0

 

1.17 Write a program to convert Celsius to Fahrenheit

 

c=float(input("Enter The Celsius : "))

f=((9*c)/5)+32;

print("Fahrenheit : ",f);

Output:

 

Enter The Celsius : -40

Fahrenheit :  -40.0

1.18 Write a program to convert Fahrenheit to Celsius

f=float(input("Enter The Fahrenheit  : "))

c=((f-32)*5)/9;

print("Celsius: ",c);

 

Output

 

Enter The Fahrenheit  : -40

Celsius:  -40.0

1.19 Write a C program for swapping of two numbers.

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

c=a;

a=b;

b=c;

print("Value of a = ",a);

print("Value of b = ",b);

 

Output

 

Enter 1st number : 10

Enter 2nd number : 20

print("After Swap = ",a);

print("After Swap = ",b);

 

1.20 Write a C program for swapping of two numbers without using a third variable.  

 

a=int(input("Enter 1st number : "));

b=int(input("Enter 2nd number : "));

a=a+b;

b=a-b;

a=a-b;

print("After Swap = ",a);

print("After Swap = ",b);

 

Output

 

Enter 1st number : 10

Enter 2nd number : 20

print("After Swap = ",a);

print("After Swap = ",b);

 

1.21  If a five digit number is input through the keyboard, write a program to reverse the number.

 

a=int(input("Enter The Five Digit Number : "));

b=0

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

b=b*10+a%10;

a=int(a/10);

print("The Reverse of the Number = ",b);

 

Output

 

Enter The Five Digit Number : 12345

The Reverse of the Number =  54321

1.22  If a four digit number is input through the keyboard, write a program to the sum of the first and last digit of this number.

 

a=int(input("Enter The Five Digit Number : "));

b=a%10;

a=int(a/10);

m=b;

b=a%10;

a=int(a/10);

b=a%10;

a=int(a/10);

b=a%10;

a=int(a/10);

b=a%10;

a=int(a/10);

n=b;

x=n+m;

print("The Sum Of The First And Last Digit = ",x);

 

 

Output

 

Enter The Five Digit Number : 12345

The Sum Of The First And Last Digit =  6

 

1.23  In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

 

totpop=80000;

totmen=(52.0/100.0)*totpop;

totlit=(48.0/100.0)*totpop;

litmen=(35.0/100.0)*totpop;

ilitmen=totmen-litmen;

totlitwomen=totlit-litmen;

totwomen=totpop-totmen;

ilitwomen=totwomen-totlitwomen;

print("Total number of men in the town is : ",totmen);

print("Total number of literate in the town is : ",totlit);

print("Total number of literate men in the town is : ",totmen);

print("Total number of women id : ",totwomen);

print("Total number of illiterate men is : ",ilitmen);

print("Total number of illiterate women is : ",ilitwomen);      

Output

 

Total number of men in the town is :  41600.0

Total number of literate in the town is :  38400.0

Total number of literate men in the town is :  41600.0

Total number of women id :  38400.0

Total number of illiterate men is :  13600.0

Total number of illiterate women is :  28000.0

1.24  A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

amount=int(input("Enter The Amount To Be Withdrawn Rs."))

nohun=amount/100;

nofifty=amount/50;

noten=amount/10;

print("Number Of Hundred Notes Required =  ",nohun);

print("Number Of Fifty Notes Required =  ",nofifty);

print("Number Of Ten Notes Required = ",noten);

 

Output

 

Enter The Amount To Be Withdrawn Rs.500

Number Of Hundred Notes Required =   5.0

Number Of Fifty Notes Required =   10.0

Number Of Ten Notes Required =  50.0

1.25  If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.

 

sp=float(input("Enter The Total Selling Price Rs."))

profit=float(input("Enter The Total Selling Profit Rs."))

cp=sp-profit;

cp=cp/15;

print("Cost Price Per Item Is Rs. =  ",cp);

Output

 

Enter The Total Selling Price Rs.500

Enter The Total Selling Profit Rs.200

Cost Price Per Item Is Rs. =   20.0

1.26 if a five –digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if that number is input is 12391 the output should be displayed as 23402.

 

num=int(input("Enter A 5 Digit Number (Less Than 32767) : "));

newnum=0;

a=int(num/10000+1);

n=int(num%10000);

newnum=int(newnum+a*10000);

 

a=int(n/1000+1);

n=int(n%1000);

newnum=int(newnum+a*1000);

 

a=int(n/100+1);

n=int(n%100);

newnum=int(newnum+a*100);

 

a=int(n/10+1);

n=int(n%10);

newnum=int(newnum+a*10);

 

a=int(n+1);

newnum=int(newnum+a);

 

print("The New Numbers Are : = ",newnum);

 

 Output

 

Enter A 5 Digit Number (Less Than 32767) : 12391

The New Numbers Are : =  23502

 

 

No comments:

Post a Comment

JAVA PROGRAMMING - OOPS CHAPTER 1

Object-Oriented Programming Chapter 1: Basics by Souradeep Roy Using IntelliJ IDEA Community version:- _____________________________________...