Sunday, 2 July 2023

Python Programming Chapter 2 - If else

Q1.write a program using if statement:-
ans.
a=int(input("Enter the number"))
if(a>10):
    print("The number is greater than 10")
if(a<10):
    print("The number is less than 10")
if(a==10):
    print("The number is equal to 10")

Output:
Enter the number50
The number is greater than 10
----------------------------------------------------------------------------
Q2. Write a program to compare in two numbers using if statement:-
ans.
a=int(input("Enter the 1st number"))
b=int(input("Enter the 2nd number"))
if(a>b):
    print("a is greater than b")
if(a<b):
    print("a is less than b")
if(a==b):
    print("a is equal to b")

Output:
Enter the 1st number20
Enter the 2nd number30
a is less than b

-----------------------------------------------------------------------------

Q3. Write a program to check which greatest number is?
ans.
a=int(input("Enter the 1st number"))
b=int(input("Enter the 2nd number"))
c=int(input("Enter the 3rd number"))
x=-32767
if(a>x):
    x=a
if(b>x):
    x=b
if(c>x):
    x=c
print("The greatest number among three is :",x) 

Output:
Enter the 1st number12
Enter the 2nd number30
Enter the 3rd number03
The greatest number among three is : 30

----------------------------------------------------------------------------
Q4. Write a program to  check the password using if only.
ans. p=int(input("Enter the number"))
if(p==12345):
    print("Password Accepted")
if(p!=12345):
    print("Password Denied")
    
Output:
Enter the number12345
Password Accepted
-----------------------------------------------------------------------------------

Q5. Write a program to check whether an age is able to voting or not?
Ans.
a=int(input("enter your age="))
if a>=18:
    print("eligible to vote")
else:
    print("Not eligible to vote")

Output:
enter your age=18
eligible to vote
---------------------------------------------------------------------------------

Q6. Find out the Maximum number using the if statement?
ans.
a=int(input("Enter 1st no="))
b=int(input("Enter 2nd no="))
if a>b:
    print("a is max number");
else:
     print("b is max number");

Output:
Enter 1st no=20
Enter 2nd no=10
a is max number
----------------------------------------------------------------------------------

Q7. Write a program to check whether a given number is positive, negative or zero.
ans.
a=int(input("Enter the number="))
if a>0:
    print("The number is positive")
elif  a<0:
    print("The number is negative")
if a==0:
    print("Zero")

Output:
Enter the number=20
The number is positive
---------------------------------------------------------------------------------

Q8. Write a program to find the middle number in a group of three numbers.
ans.
a=int(input("Enter 1st number="))
b=int(input("Enter 2nd number="))
c=int(input("Enter 3rd number="))
if (a>b and a<c) or (a>b and a>c):
    print("middle number= ",a)
elif (b>a and b<c) or (b<a and b>c):
    print("middle number= ",b)
else:
    print("middle number=",c)

Output:
Enter 1st number=10
Enter 2nd number=15
Enter 3rd number=20
middle number=  15
----------------------------------------------------------------------------

Q9. Calculate the total marks-
ans.
a=int(input("Enter 1st number="))
b=int(input("Enter 1st number="))
c=int(input("Enter 1st number="))
d=int(input("Enter 1st number="))
e=int(input("Enter 1st number="))
total=a+b+c+d+e
percent=(total/500)*100
print("Total marks=",total, "percent=",percent)
if percent >= 80:
    print("You have got Grade A")
elif percent >= 60:
    print("You have got Grade B")
elif percent >= 40:
    print("You have got Grade C")
else:
    print("Fail")

--------------------------------------------------------------------------

Q10. Write a program check you are an indian or not.
ans.
ans=int(input("Enter your ans: "))
if(ans==1):
    age=int(input("Enter your age:"))
    if(age>=18):
        print("You can vote")
    else:
        print("You can not vote")
else:
    print("You can not access because you are not an indian")

Output:
Enter your ans: 1
Enter your age:20
You can vote
---------------------------------------------------------------------------
Q11. Write a program you ar eligible or not for get concession.
ans.
age=int(input("Enter your age: "))
if(((age>=3)and(age<=11))or((age>=60)and(age<=100))):
    print("You can get concession")
else:
    print("You can not get concession")
        
Output:
Enter your age: 20
You can not get concession
--------------------------------------------------------------------------

Q12. Write a program to check a triangle is perfect or not.
ans.
a=int(input("Enter the 1st angle of a triangle: "))
b=int(input("Enter the 2nd angle of a triangle: "))
c=int(input("Enter the 3rd angle of a triangle: "))
if(a+b+c==180):
    print("Perfect triangle")
else:
    print("Not")
        
Output:
Enter the 1st angle of a triangle: 50
Enter the 2nd angle of a triangle: 100
Enter the 3rd angle of a triangle: 50
Not
--------------------------------------------------------------------------

Q13. Write a program to check a rectangle whether it is perfect rectangle or not?
ans.
a=int(input("Enter the 1st angle of a rectangle: "))
b=int(input("Enter the 2nd angle of a rectangle: "))
c=int(input("Enter the 3rd angle of a rectangle: "))
d=int(input("Enter the 4th angle of a rectangle: "))
if(a+b+c+d==360):
    print("Perfect rectangle")
else:
    print("Not")
        
Output:
Enter the 2nd angle of a rectangle: 50
Enter the 3rd angle of a rectangle: 100
Enter the 4th angle of a rectangle: 160
Perfect rectangle
---------------------------------------------------------------------------

Q14. Write a program to check is there any supply needs as for the respect of demand.
ans.
demand=int(input("Enter the demand"))
supply=int(input("Enter the supply"))
if(demand>=supply):
    need=demand-supply
    print("We need to purchased")
else:
    print("We have not need to purchased")

Output:
Enter the demand 250
Enter the supply 300
We have not need to purchased
----------------------------------------------------------------------------------

Q15. Write a program to check a year whether it is leap year or not.
ans.
year=int(input("Enter the year: "))
if(year%4==0):
    print("This is leap year")
else:
    print("This is not a leap year")

Output:
Enter the year: 2020
This is leap year
----------------------------------------------------------------------------------------

Q16. Write a program to determine a number is odd or even.
Ans.
a=int(input("Enter the number: "))
if(a%2==0):
    print("This is Odd number")
else:
    print("This is Even number")

Output:
Enter the number: 25
This is Even number
----------------------------------------------------------------------------------------

Q17. Write a program to cast vote for certain age.
ans.
Age=int(input("Enter your age:"))
if((Age>=18)and(Age<=30)):
    print("You can vote")
else:
    print("You can not vote")
    
Output:
Enter your age:25
You can vote
------------------------------------------------------------------------------------

Q18. Write a program to determine whether discount of 10% will be allowed if purchase price will exceed Rs 5000.
ans.
pn=input("Enter your product name:")
rate=int(input("Enter your rate:"))
qty=int(input("Enter your quantity:"))
pr=rate*qty
if(pr>=5000):
    disp=pr-pr*.1
    price("price after 10%% discount=Rs",disp)
else:
    print("No discount allowed as price")
    
Output:
Enter your product name:lux
Enter your rate:20
Enter your quantity:30
No discount allowed as price
---------------------------------------------------------------------------------------------
Q19. WAP to find the dates in a month
ans. 

m=int(input("enter the month no:"))
if(m==1):
    print("January")
elif(m==2):
    print("February")
elif(m==3):
    print("March")
elif(m==4):
    print("April")
elif(m==5):
    print("May")
elif(m==6):
    print("June")
elif(m==7):
    print("July")
elif(m==8):
    print("Augest")
elif(m==9):
    print("September")
elif(m==10):
    print("October")
elif(m==11):
    print("November")
elif(m==12):
    print("December")

   
Output:
enter the month no:5
May
--------------------------------------------------------------------------------------------

No comments:

Post a Comment

JAVA PROGRAMMING - OOPS CHAPTER 1

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