Python Language

Basic Programming

1. WAP to print “Hello Word".

	print("hello world")
	

2. WAP to input 2 numbers and print addition, subtraction, multiplication, division.

	n1=int(input("enter first number"))
	n2=int(input("enter second number"))
	add=n1+n2
	sub=n1-n2
	mul=n1*n2
	div=n1/n2
	print("addition is",add)
	print("substraction is",sub)
	print("multiplication is",mul)
	print("division is",div)
	

3. WAP to input 3 numbers and print average.

	n1=int(input("enter first number"))
	n2=int(input("enter second number"))
	n3=int(input("enter third number"))
	avg=n1+n2+n3/3
	print("average of three numbers are",avg)
	

4. WAP to input a number and print square and cube.

	n1=int(input("enter first number"))
	sq=n1*n1
	cube=n1*n1*n1
	print("square of a number",sq)
	print("cube of a number",cube)
	

5. WAP to input marks of 5 subjects and print total marks and percentage.

	eng=int(input("enter english marks"))
	hin=int(input("enter hindi marks"))
	math=int(input("enter maths marks"))
	sci=int(input("enter science marks"))
	sst=int(input("enter sst marks"))
	total=eng+hin+math+sci+sst
	per=total/5
	print("total marks of subjects",total)
	print("percentage",per)
	

6. WAP to input radius of circle and print area and circumference.

	r=int(input("enter radius of a circle"))
	area=22/7*r*r
	cir=2*22/7*r
	print("area of circle",area)
	print("circumference of circle",cir)
	

7. WAP to input 2 numbers and swap their values using the 3rd variable.

	a=int(input("enter first number"))
	b=int(input("enter second number"))
	x=a
	a=b
	b=x
	print("value of a",a)
	print("value of b",b)
	

8. WAP to input 2 numbers and swap their values without using the 3rd variable.

	a=int(input("enter first number"))
	b=int(input("enter second number"))
	a=a+b
	b=a-b
	a=a-b
	print("value of a",a)
	print("value of b",b)
	

9. WAP a program to input time in second and convert into Hours, min and second.
Example. 72 sec = 0 Hr 1 min 12 sec

	sec=int(input("enter time in sec"))
	h=sec//3600
	a=sec%3600
	m=a//60
	s=a%60
	print(h,"hours",m,"minute",s,"seconds")
	

10. WAP to input amount in paise and convert into rupees and paise.
Ex. 120 paisa = 1 Rs 20 Paisa

	cur=int(input("enter currency"))
	r1=int(cur/100)
	r2=cur%100
	print(r1,"rupees",r2,"paisa")
	

11. WAP to input side and calculate area of square.

	a=int(input("enter side of a square"))
	area=a*a
	print("area of a sqaure",area)
	

12. WAP to input length and breadth and calculate area of rectangle.

	l=int(input("enter length of a rectangle"))
	b=int(input("enter breadth of a rectangle"))
	area=l*b
	print("area of a rectangle",area)
	

13. WAP to input value of a & b and calculate value of expression : a2 +b2 +2ab

	a=int(input("enter value of a"))
	b=int(input("enter value of b"))
	c=a*a+b*b+2*a*b
	print("answer is",c)
	

14. WAP to input a number and print the next 3 numbers.

	n=int(input("enter a number"))
	n1=n+1
	n2=n1+1
	n3=n2+1
	print("next three numbers are",n1,n2,n3)
	

15. WAP to input a number and print previous 3 numbers.

	n=int(input("enter a number"))
	n1=n-1
	n2=n1-1
	n3=n2-1
	print("next three numbers are",n1,n2,n3)
	

16. WAP to input sales amount and calculate 18% GST.

	sal=int(input("enter sales"))
	gst=sal*18/100
	print("18% gst on sales is",gst)
	

17. WAP to input monthly salary and print annual salary after 12% deduction of Income tax.

	ms=int(input("enter monthly salary"))
	b=ms*12
	it=b*12/100
	print("annual salary after 12% income tax",it)
	

18. WAP to input rate of 1 fan and calculate total amount of 1 dozen fan with 5% GST.

	f=int(input("enter cost of one fan"))
	d=f*12
	gst=d*12/100
	cost=d+gst
	print("cost of one dozon fan after 12% gst",cost)
	

if - else

1. Write a program to input a number and check if the number is positive or negative?

	no=int(input("Enter a number"))
	if no>0:
		print("Positive Number")
	else:
		print("Negative Number")
	

2. Write a program to input two numbers and print the largest number between the numbers?

	a=int(input<"Enter a number"))
	b=int(input("Enter b number"))
	if a>b:
		print("Largest Number is :",a)
	else:
		print("Largest Number is :",b)
	

3. Write a program to input two numbers and print the square of the smallest number between the numbers?

	a=int(input<"Enter a number"))
	b=int(input("Enter b number"))
	if a< b:
		print("Largest Number is :",a)
		print("Squre is :",a*a)
	else:
		print("Largest Number is :",b)
		print("Squre is :",b*b)
	

4. Write a program to input your age and check if the user can vote or not?

	age=int(input("Enter your Age :"))
	if age>=18:
		print("User can vote")
	else:
		print("User can't vote")
	

5. Write a program to input the monthly salary and calculate the yearly salary if yearly salary is greater than 2 lakh calculate 10% income tax otherwise 8% income tax?

	ms=int(input("Enter your monthlyb salary :"))
	ys=ms*12
	print("Yearly salary is ",ys)
	if ys>200000:
		tax=ys*10/100
		print("Tax is ",tax)
	else:
		tax=ys*8/100
		print("Tax is ",tax)
	

6. Write a program to input the marks of 5 subjects and calculate the total marks and percentage if the percentage is greater than 60% print pass otherwise fail?

	eng=int(input("enter english marks"))
	hin=int(input("enter hindi marks"))
	math=int(input("enter maths marks"))
	sci=int(input("enter science marks"))
	sst=int(input("enter sst marks"))
	total=eng+hin+math+sci+sst
	print("total marks of subjects",total)
	per=total/5
	print("percentage",per)
	if per>60:
		print("Result is Pass ")
	else:
		print("Result is Fail ")
	

7. Write a program to input a number and check if the number is even or odd?

	no=int(input("Enter a Number :"))
	if no%2==0:
		print("Even")
	else:
		print("Odd")
	

8. Write a program to input a year and check if the year is leap year or not?

	year=int(input("Enter a year :"))
	if year%4==0:
		print("Leap Year")
	else:
		print("Not Leap Year")
	

9. Write a program to input your age and check if the user is a senior citizen or not ?

	age=int(input("Enter your age :"))
	if age>60:
		print("Senior Citizen")
	else:
		print("Not a Senior Citizen")
	

10. Write a program to input a number and check if the given number is a buzz number or not ?

	no=int(input("Enter a Number :"))
	if no%10==7 or no%7==0:
		print("Buzz Number")
	else:
		print("Not Buzz Number")
	

11. Write a program to input a character and check if the given character is vowel or consonant ?

	chr=input("Enter a Character :")
	if chr in "AEIOUaeiou":
		print("Vowel")
	else:
		print("Consonent")
	

12. Write a program to input sales if sales is greater than 200000 calculate 5% tax otherwise no tax ?

	sal=int(input("Enter your sales"))
	if sal>200000:
		tax=sal*5/100
		print("Tax is ",tax)
	else:
		print("No Tax")
	

if - else ladder

1. WAP to input 3 numbers and print the largest number.

	a=int(input("Enter a Number"))
	b=int(input("Enter b Number"))
	c=int(input("Enter c Number"))
	if a>b and a>c:
		print("Largest Number is ",a)
	elif b>a and b>c:
		print("Largest Number is ",b)
	else:
		print("Largest Number is ",c)
	

2. WAP to input 3 numbers and print the smallest number.

	a=int(input("Enter a Number"))
	b=int(input("Enter b Number"))
	c=int(input("Enter c Number"))
	if a< b and a< c:
		print("Largest Number is ",a)
	elif b< a and b< c:
		print("Largest Number is ",b)
	else:
		print("Largest Number is ",c)
	

3. WAP to input percentage from user and print division where,
0 to 32 -Fail
33 to 44 - Third
45 to 59 - Second
60 to 74 - First
75 to 100 - Honours
Otherwise - Wrong Percentage

	per=int(input("Enter your Percentage :"))
	if per>0 and per<=32:
		print("Fail")
	elif per>=33 and per<=44:
		print("Third")
	elif per>=45 and per<=59:
		print("Second")
	elif per>=60 and per<=74:
		print("First")
	elif per>=75 and per<=100:
		print("Honours")
	else:
		print("Wrong percentage")
	

4. WAP to input the electricity unit from the user and calculate electric bill where.
0 to 100 unit - 6Rs/Unit
101 to 200 - 6.25Rs/Unit
201 to 400 - 6.5Rs/Unit
401 to more - 7.0Rs/Unit

	unit=int(input("Enter your Unit :"))
	if unit>0 and unit<=100:
		bill=unit*6
		print("Bill is ",bill)
	elif unit>=101 and unit<=200:
		bill=unit*6.25
		print("Bill is ",bill)
	elif unit>=201 is unit<=400:
		bill=unit=6.5
		print("Bill is ",bill)
	else:
		bill=unit*7
		print("Bill is ",bill)
	

5. WAP to input salary from employee and calculate income tax where,
0 to 5L - 0%
Next 10L - 10%
Next 10L - 12.5%
Next 10L - 15%
Next 10L - 20%
After 45L - 30%

	sal=int(input("Enter your Salary"))
	if sal>0 and sal<=500000:
		print("Tax is 0%")
	elif sal>=500000 and sal<=1500000:
		tax=sal*10/100
		print("Tax is ",tax)
	elif sal>=1500000 and sal<=2500000:
		tax=sal*12.5/100
		print("Tax is ",tax)
	elif sal>2500000 and sal<=3500000:
		tax=sal*15/100
		print("Tax is ",tax)
	elif sal>3500000 and sal<=4500000:
		tax=sal*20/100
		print("Tax is ",tax)
	else:
		tax=sal*30/100
		print("Tax is ",tax)
	

6. WAP to input call and calculate telephone bill where,
0 to 100 call - 2Rs/call
Next 100 Call - 1.5Rs/call
Next 100 Call - 1Rs/call
After 300 call - .50Rs/call

	call=int(input("Enter your calls"))
	if call>0 and call<=100:
		bill=call*2
		print("Bill is ",bill)
	elif call>=101 and call<=200:
		bill=call*1.5
		print("Bill is ",bill)
	elif call>=201 and call<=300:
		bill=call*1
		print("Bill is ",bill)
	else:
		bill=call*0.50
		print("Bill is ",bill)
	

7. WAP to input no of working days in year and calculate yearly salary where,
0 to 100 days - Rs. 500 per day
101 to 200 days - Rs. 1000 per day
201 to 300 days - Rs. 1500 per day
301 to 365 days - Rs. 2000 per day
After 365 days - Wrong Input

	days=int(input("Enter your working days"))
	if days>0 and days<=100:
		print("salary is =",days*500)
	elif days>=101 and days<=200:
		print("salary is ",days*1000)
	elif days>=201 and days<=300:
		print("salary is ",days*1500)
	elif days>=301 and days<=365:
		print("salary is ",days*2000)
	else:
		print("Wrong Input")
	

WAP to creat a manu driven calculater

	a=int(input("Enter 1 Number :"))
	b=int(input("Enter 2 Number :"))
	print("1. Addition")
	print("2. Substraction")
	print("3. Multiplication")
	print("4. Division")
	ch=int(input("Enter your choice"))
	if ch==1:
		print(a+b)
	elif ch==2:
		print(a-b)
	elif ch==3:
		print(a*b)
	if ch==4:
		print(a/b)
	

Nested if - else

1. WAP to input age and gender "M,F" of user than discount amount
gender age discount
M <60 20%
m >=60 30%
F <60 15%
f >=60 25%

	gen=input("Enter Your Gender :")
	age=int(input("Enter your age :))
	if gen=="M" or gen=="m"
		if age<60:
			print("20% discount")
		else:
			print("30% discount")
	elif gen=="F" or gen=="f"
		if age<60:
			print("15% discount")
		else:
			print("25% discount")
	

2. WAP to input three number and find the smallest number using nested if

	a=int(input("Enter a number :"))
	b=int(input("Enter b number :"))
	c=int(input("Enter c number :"))
	if a < c:
		if a < b:
			print("Smallest number a ",a)
		else:
			print("Smallest number b ",b)
	elif b < c:
		print("Smallest number b ",b)
	else:
		print("Smallest number c ",c)
	

3. WAP to input electricity meter connection type 'C' or 'D' than calculate electric bill according to given unit by user
meter bype unit Rate fc
D <200 3/unit 100
d >=200 4.5/unit 200
C <200 5/unit 400
c >=200 7/unit 600

	mt=input("Enter meter type :")
	unit=int(input("Enter unit :"))
	if mt=="D" or mt=="d":
		if unit<200:
			print((unit*3)+100)
		else:
			print((unit*4.5)+200)
	elif mt=="C" or mt=="c":
		if unit<200:
			print((unit*5)+400)
		else:
			print((unit*7)+600)
	

4. WAP to input age gender and ticket amount of pecenger and print discount ticket amount according to given condition gen age Discount M <60 10%
m >=60 25%
F <60 20%
f >=60 40%

	gen=input("Enetr gender :")
	age=int(input("Enter your age :"))
	ticket=int(input("Enter ticket amount "))
	if gen=="M" or gen=="m":
		if age<60:
			print(ticket-(ticket*10)/100)
		else:
			print(ticket-(ticket*25)/100)
	elif gen=="F" or gen=="f":
		if age<60:
			print(ticket-(ticket*20)/100)
		else:
			print(ticket-(ticket*40)/100)
	else:
		print("Wrong input")
	

For Loop

while loop

Nested loop

Function

File