0% found this document useful (0 votes)
47 views

Python Programming Dated 16-07-2021

The document contains 14 questions related to Python programming. The questions cover topics like inputting values, performing calculations using simple mathematical and logical operators, conditional statements like if, else, if-else and nested if-else. Some key questions include: Q1 to calculate simple interest, Q2 to swap two numbers using a third variable, Q3 to swap two numbers without using a third variable, Q4 to calculate net salary based on input values, Q5 to calculate net salary using predefined percentages, Q6 to calculate total, percentage and average marks based on input marks. The document also covers conditional statements like finding even/odd numbers, leap years, largest/smallest numbers among inputs.

Uploaded by

Raghav Agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Python Programming Dated 16-07-2021

The document contains 14 questions related to Python programming. The questions cover topics like inputting values, performing calculations using simple mathematical and logical operators, conditional statements like if, else, if-else and nested if-else. Some key questions include: Q1 to calculate simple interest, Q2 to swap two numbers using a third variable, Q3 to swap two numbers without using a third variable, Q4 to calculate net salary based on input values, Q5 to calculate net salary using predefined percentages, Q6 to calculate total, percentage and average marks based on input marks. The document also covers conditional statements like finding even/odd numbers, leap years, largest/smallest numbers among inputs.

Uploaded by

Raghav Agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

14/07/2021

Q1 Write a program to input principal Amount rate and time and calculate simple
interest.

p=int(input("Enter principal Amount"))


r=int(input("Enter Rate"))
t=int(input("Enter Time"))
si=(p*r*t)/100
print("The Simple Interest is",si)

Q2. Write a program to input two numebrs and swap their values using third variable
Swapping: Interchanging values of variable is called Swapping
Teachinque used in swapping
1) Using third variable
2) Without using third varaible

a=int(input("before Swapping Enter value of a"))


b=int(input("before Swapping Enter value of b"))
c=a
a=b
b=c
print("After Swapping the value of a is",a)
print("After Swapping thr value of b is",b)

Q3. Write a program to input two numbers and swap their values without using third
variable.

a=int(input("before Swapping Enter value of a"))


b=int(input("before Swapping Enter value of b"))
a=a+b
b=a-b
a=a-b
print("After Swapping the value of a is",a)
print("After Swapping thr value of b is",b)

a=10
b=5
a=a+b =10+5 a=15
b=a-b =15-5 b=10
a=a-b=15-10 a=5

Q4. Write a program to input basic salary, da, hra, pf and calculate net salary.
net=basic+da+hra-pf

basic=int(input("Enter basic Salary"))


da=int(input("Enter Daily Allowance DA"))
hra=int(input("Enter House Rent Allowance HRA"))
pf=int(input("Enter Provident Fund Pf"))
net=basic+da+hra-pf
print("The net Salary is",net)

Q5. Write a program to input basic salary and calcualte net salary.
da=50% of basic salary
hra=30% of basic salary
pf=10% of basic salary
net=basic+da+hra-pf
basic=float(input("Enter basic Salary"))
da=(basic*50)/100
hra=(basic*30)/100
pf=(basic*10)/100
net=basic+da+hra-pf
print("The basic salary is",basic)
print("The Da is",da)
print("The hra is",hra)
print("The pf is",pf)
print("The net Salary is",net)

Q6 Write a program to input marks in five subject out of 100 and calculate total
marks,
percentage marks, average marks.

sname=input("Enter Student Name")


eng=float(input("Enter marks in english out of 100"))
math=float(input("Enter marks in maths out of 100"))
phy=float(input("Enter marks in Physics out of 100"))
chem=float(input("Enter marks in Chemistry out of 100"))
comp=float(input("Enter marks in Computer Science out of 100"))
total=eng+math+phy+chem+comp
per=(total/500)*100
avg=total/5
print("___________________________")
print("REPORT CARD OF:",sname)
print("___________________________")
print("The Total marks is",total)
print("The percentage marks is",per)
print("The Average marks is",avg)

15/07/2021

Q7 Write a program to input principal Amount rate and time and calculate
amount and compound interest.

p=float(input("Enter principal Amount"))


r=float(input("Enter Rate"))
t=float(input("Enter Time"))
a=p*(1+r/100)**t
i=a-p
print("The Amount is",a)
print("The Interest is",i)

Q8. Write a program to input 3 sides of a triangle and calcualte area of triangle
using
heros formaula.

a=int(input("Enter First Side of a Triangle"))


b=int(input("Enter Second Side of a Triangle"))
c=int(input("Enter Third Side of a Triangle"))
s=(a+b+c)/2
a=(s*(s-a)*(s-b)*(s-c))**0.5
print("The Area of Triangle is",a)
Q9. Write a parogram to input any number and find out the last digit of that
number.

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


b=a%10
print("The Last Digit of the number is",b)

#Note:

#b=a%10
# Divide the number a by 10 and remainder will store in variable.

Q10 Write a program to input any Five Digit number and find out the sum of its
first and last digit.

a=int(input("Enter Any Five Digit number"))


b=a//10000
c=a%10
d=b+c
print("The Sum of First and last Digit is",d)

#Tracing
# a=12345 input
# b=a//10000 b=12345//10000 b=1
# c=a%10 =12345%10 c=5
# d=b+c =1+5=6

___________________________________________________________________________________
______

Type-2
Programs based on Conditional
Statement
if statement:
in this statenent first condition is checked and if the condtion is true then
statements are executed. if the condition is false then no statement is
executed.
Syntax:
if(Conditon):
Statement to be executed when condition is True

Example:
WAP to input your age and if your age is greater than equal to 18 then
display the message you are eligible for vote. otherwise display the
message you are not eligible for vote.

age=int(input("Enter your age"))


if(age>=18):
print("You are Eligible for vote")
if(age<18):
print("You are not Eligible for vote")

if..else statement
in this statenent first condition is checked and if the condtion is true then
a set of statement is executed if the conditon is false then another set of
statement is executed.
if(Conditon):
Statement to be executed when condition is True
else:
Statement to be executed when condition is False

Example:
WAP to input your age and if your age is greater than equal to 18 then
display the message you are eligible for vote. Otherwise display the
message you are not eligible for vote.

age=int(input("Enter your age"))


if(age>=18):
print("You are Eligible for vote")
else:
print("You are not Eligible for vote")

Example" WAP to input any number and check whether the entered number is
even or odd.

a=int(input("Enter Any Number"))


if(a%2==0):
print("Even Number")
else:
print("odd Number")

Example" WAP to input year number and check whether the entered year is
leap year or not.

year=int(input("Enter Year Number"))


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

16/07/2021

if..elif..else statement:

This statement allows us to test number of conditions in the program the condition
which is evaluated to true then statement present on that condtion will be exceuted
if no condition is evaluated to true then statement present on else will be
executed.

Syntax:
if(condtion 1):
statement to be exceuted when condition 1 is true
elif(condtion 2):
statement to be exceuted when condition 2 is true
elif(condtion 3):
statement to be exceuted when condition 3 is true
elif(condtion 4):
statement to be exceuted when condition 4 is true
elif(condtion 5):
statement to be exceuted when condition 5 is true
:
:
:
else:
statement to be exceuted when condition is false

Q1 Write a program to input any number and check whether the entered number is
negative, positive or zero.

a=int(input("Enter Any Number"))


if(a>0):
print("+Ve Number")
elif(a<0):
print("-ve Number")
else:
print("Number is zero")

H.W.
Q2 Write a program to input day number and display week day using if..elif..else
statement.

d=int(input("Enter Day Number"))


if(d==1):
print("Sunday")
elif(d==2):
print("Monday")
elif(d==3):
print("Tuesday")
elif(d==4):
print("Wednesday")
elif(d==5):
print("Thursday")
elif(d==6):
print("Friday")
elif(d==7):
print("Saturday")
else:
print("Invalid Day Number Entered")

Q3. Write a program to input month number and print month name using if..elif..else
statement.

Q4. Write a program to input two numbers and find out the largest number.
a=int(input("Enter First Number"))
b=int(input("Enter Second Number"))
if(a>b):
print("Largest Number is",a)
elif(b>a):
print("Largest Number is",b)
else:
print("Both Numbers are equal")

Q5 Write a program to input three number and find out the largest number.

a=int(input("Enter First Number"))


b=int(input("Enter Second Number"))
c=int(input("Enter Third Number"))
if(a==b and b==c and c==a):
print("All three numbers are equal")
elif(a>=b and a>=c):
print("Largest Number is",a)
elif(b>=a and b>=c):
print("Largest Number is",b)
elif(c>=a and c>=b):
print("Largest Number is",c)

Q6 Write a program to input four number and find out the largest number.

a=int(input("Enter First Number"))


b=int(input("Enter Second Number"))
c=int(input("Enter Third Number"))
d=int(input("Enter Fourth Number"))
if(a==b and b==c and c==d and d==a):
print("All Four numbers are equal")
elif(a>=b and a>=c and a>=d) :
print("Largest Number is",a)
elif(b>=a and b>=c and b>=d):
print("Largest Number is",b)
elif(c>=a and c>=b and c>=d):
print("Largest Number is",c)
elif(d>=a and d>=b and d>=c):
print("Largest Number is",d)

H.W.
Q7 Write a program to input five number and find out the largest number.
Q8 Write a program to input six number and find out the largest number.
Q9. Write a program to input two numbers and find out the smallest number.
Q10 Write a program to input three number and find out the smallest number.
Q11 Write a program to input four number and find out the smallest number.
Q12 Write a program to input five number and find out the smallest number.
Q13 Write a program to input six number and find out the smallest number.

Q14 Write a program in python that will ask the user to input two numbers and
an operator ( + , - , * , /)and then perform addition, substraction,
multiplication and division
and finally display result.

a=int(input("Enter First Number"))


b=int(input("Enter Second Number"))
oper=input("Enter Operator + , - , * , /")
if(oper=='+'):
c=a+b
print("The Sum is",c)
elif(oper=='-'):
c=a-b
print("The Difference is",c)
elif(oper=='*'):
c=a*b
print("The Multiplication is",c)
elif(oper=='/'):
c=a/b
print("The Division is",c)
else:
print("Invalid Operator Entered")

You might also like