[go: up one dir, main page]

0% found this document useful (0 votes)
62 views13 pages

Find the output of the following codes

Uploaded by

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

Find the output of the following codes

Uploaded by

Eshika Tomer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Find the output of the following codes:

S. PROGRAM OUTPUT
N
O
1. a = 10 a
if a==10:
print("a")
else:
print("b")

2. a = 10 a
if a:
print("a")
else:
print("b")

3. a=0 b
if a:
print("a")
else:
print("b")

4. a=5 b
if a>10 and a<20: c
print("a")
if a>10 or a<20:
print("b")
if a==5:
print("c")
else:
print("d")

5. a=5 b
if a==5:
if a>4 and a<2:
print("a")
elif a>2 or a<1:
print("b")
else:
if a>4 or a<2:
print("a")
elif a>2 and a<1:
print("b")

6. a = int(input("Enter the Number")) Enter the


if a==1: Number
print("a") 2
elif a==2: b
print("b")
elif a==2:
print("c")
elif a==3:
print("d")
elif a==4:
print("e")
elif a==5:
print("f")
else:
print("Wrong input")

7. a = 2.25 <class 'float'>


if type(a) == int:
print("int")
else:
if type(a) == float:
print(float)
elif type(a)==str:
print(str)

8. a = 3+2j Invalid Number


if a.imag == 0:
print("Real Number")
elif a.real == int:
print("complex number")
else:
print("Invalid Number")

9. a = 10 Id is same
b = 10
if id(a) == id(b):
print("Id is same")
else:
print("Id is not same")

1 if(4+5==10): False
0. print("True") True
else:
print("False")
print("True")
Write the Python Program for the following:

11. Accept the age, sex (‘M’, ‘F), number of days and display the
wages accordingly
Age Sex
Wage/day
>=18 and <30 m M
700
F 750
>=30 and <=40 m M
800
F 850
If age does not fall in any range then display the following
message: “Enter appropriate age”

ANS PROGRAM OUTPUT


.
a=int(input("enter your age = ")) enter your
b=input("enter your sex = ") age = 26
if ord(b)==102 or ord(b)==70: enter your sex
if 18<=a<30: =M
print("your wage is 750") your wage is
elif 30<=a<=40: 700
print(" your wage is 850")
if ord(b)==77 or ord(b)==109:
if 18<=a<30:
print("your wage is 700")
elif 30<=a<=40:
print(" your wage is 800")
else:
print("Enter appropriate age")
else:
print("Enter appropriate age")

12. Accept the percentage from the user and display the grade
according to the following criteria:
Below25—D
25to45 —C
45t0o50—B
50 to 60 — B+
60to 80 —A
Above 80- A+

ANS PROGRAM
. a=int(input("enter your percentage = "))
if a<25:
print(" YOUR GRADE IS 'D' ")
elif 25<=a<45:
print(" YOUR GRADE IS 'C' ")
elif 45<=a<50:
print(" YOUR GRADE IS 'B' ")
elif 50<=a<60:
print(" YOUR GRADE IS 'B+' ")
elif 60<=a<80:
print(" YOUR GRADE IS 'A' ")
elif 80<=a<=100:
print(" YOUR GRADE IS 'A+' ")
else:
print(" ENTER APPROPRIATE PERCENTAGE")
OUTPUT
enter your percentage = 94

YOUR GRADE IS 'A+'


13. Accept the following from the user and calculate the
percentage of class attended:
a. Total number of working days
b. Total number of days for absent
After calculating percentage show that, If the percentage is
less than 75, than student will not be able
to sit in exam.

ANS PROGRAM
. a=int(input("enter Total number of working days = "))
b=int(input("enter Total number of days for absent =
"))
c=a-b
d=c/a*100
print(" YOUR PRESENT PERCENTAGE IS ",d,"%")
if d>=75:
print(" YOU ARE ABLE TO SIT IN THE EXAM")
else:
print("YOU ARE NOT ABLE TO SIT IN THE EXAM")
OUTPUT
enter Total number of working days = 100
enter Total number of days for absent = 5
YOUR PRESENT PERCENTAGE IS 95.0 %
YOU ARE ABLE TO SIT IN THE EXAM

14. Accept the electric unit from the user and calculate the bill
according to the following rates.
First 100 Unit: Free
Next 200 Unit: 2 RS/Unit
Above 300 Unit: 3Rs/Unit

ANS PROBRAM
. a=int(input("enter your electric unit = "))
c=(a-100)*2
p=(a-300)*3
q=200*2
r=p+q
if a<=100:
print(" your bill is free ")
elif 100<a<=300:
print("your bill is Rs",c)
elif a>300:
print("your bill is Rs",r)
else:
print("enter appropriate units")
OUTPUT
enter your electric unit = 450
your bill is Rs 850

15. Accept the number of days from the user and calculate the
charges for library according to following:
Till Five Days : Rs 2/Day
Six to ten Days : Rs 3/Day
11 to 15 Days : Rs 4/Day
After 15 Days : Rs 5/Day

ANS PROBRAM
. a=int(input("enter the number of days= "))
b=a*2
c=(a-5)*3+10
d=(a-10)*4+25
e=(a-15)*5+45
if a<=5:
print("your charge is Rs ",b)
elif 6<=a and a<=10:
print("your charge is Rs ",c)
elif 11<=a and a<=15:
print("your charge is Rs ",d)
elif 15<a:
print("your charge is Rs ",e)
else:
print("enter appropriate days")
OUTPUT
enter the number of days= 15
your charge is Rs 45

16. Accept the kilometres covered and calculate the bill based on
given criteria :
First 10 KM : Rs 11/KM
Next 90 KM : Rs 15/KM

ANS PROBRAM
. a=int(input("enter the distance cover( in KM)= "))
b=a*11
e=(a-10)*15+110
if a<=10:
print("your bill is Rs ",b,"/km")
elif a>=11 and a<=90:
print("your charge is Rs ",e)
else:
print("enter appropriate distance")
OUTPUT
enter the distance cover( in KM)= 55
your charge is Rs 785

17. A company decided to give bonus to employee according to


following criteria:
Time period of Service Bonus
More than 10 years 10%
>=6and <=10 8%
Less than 6 years 5%
Ask user for their salary and years of service and print the
net bonus amount.

ANS PROBRAM
. a=int(input("enter your salary= "))
b=int(input("enter your years of service= "))
c=10/100*a
d=8/100*a
e=5/100*a
if b>10:
print("your net bonus is Rs ",c)
elif 6<=b and b<=10:
print("your net bonus is Rs ",d)
elif b<6:
print("your net bonus is Rs ",e)
else:
print("enter appropriate data")

OUTPUT
enter your salary= 1200000
enter your years of service= 12
your net bonus is Rs 120000.0

18. Accept the marked price from the user and calculate the Net
amount as(Marked Price - Discount) to pay according to
following criteria:
Marked Price Discount
>10000 20%
>7000 and <=10000 15%
<=7000 10%

ANS PROBRAM
. a=int(input("enter the marked price = "))
c=20/100*a
d=15/100*a
e=10/100*a
if a>10000:
print("your net amount is Rs ",a-c)
elif 7000<b and b<=10000:
print("your net amount is Rs ",a-d)
elif a<=7000:
print("your net amount is Rs ",a-e)
else:
print("enter appropriate data")
OUTPUT
enter the marked price = 50000
your net amount is Rs 40000.0

19. Write a program to accept percentage and display the


Category according to the following criteria :
Percentage Category
< 40 Failed
>=40 & <55 Fair
>=55 & <65 Good
>=65 Excellent

ANS PROBRAM
. a=int(input("enter your percentage = "))
if a<40:
print(" YOUR CATEGORY IS 'FAILED'")
elif 40<=a<55:
print(" YOUR CATEGORY IS 'FAIR'")
elif 55<=a<65:
print(" YOUR CATEGORY IS 'GOOD'")
elif 65<=a:
print(" YOUR CATEGORY IS 'EXCELLENT'")
else:
print(" ENTER APPROPRIATE PERCENTAGE")
OUTPUT
enter your percentage = 94
YOUR CATEGORY IS 'EXCELLENT'

20. Accept the marks of English, Math and Science, Social Studies
Subject and display the stream
allotted according to following
All Subjects more than 80 marks — Science Stream
English >80 and Math, Science above 50 - Commerce Stream
English > 80 and Social studies > 80 — Humanities

ANS PROBRAM
. a=int(input("enter your marks in maths = "))
b=int(input("enter your marks in english = "))
c=int(input("enter your marks in science = "))
d=int(input("enter your marks in social studies = "))
if a>80 and b>80 and c>80 and d>80:
print(" YOUR STREAM IS 'SCIENCE' ")
elif b>80 and a>50 and c>50:
print(" YOUR STREAM IS 'COMMERCE'")
elif b>80 and d>80:
print(" YOUR STREAM IS 'HUMANITIES'")
else:
print(" YOU DID NOT GET ANY STREAM")
OUTPUT
enter your marks in maths = 92
enter your marks in english = 92
enter your marks in science = 92
enter your marks in social studies = 92
YOUR STREAM IS 'SCIENCE'

21. Accept the age of 4 people find the younger one

ANS PROBRAM
. a=int(input("enter the AGE of first person = "))
b=int(input("enter the AGE of second person = "))
c=int(input("enter the AGE of third person = "))
d=int(input("enter the AGE of forth person = "))
if a<b and a<c and a<d:
print(" FIRST PERSON IS THE YOUNGEST ONE ")
elif b<a and b<c and b<d:
print(" SECOND PERSON IS THE YOUNGEST ONE ")
elif c<a and c<b and c<d:
print(" THIRD PERSON IS THE YOUNGEST ONE ")
elif d<b and d<c and d<a:
print(" FORTH PERSON IS THE YOUNGEST ONE ")
elif a==b==c==d:
print("ALL PERSON HAVE SAME AGE")
else:
print(" ENTER APPROPRIATE AGE ")
OUTPUT
enter the AGE of first person = 26
enter the AGE of second person = 24
enter the AGE of third person = 25
enter the AGE of forth person = 23
FORTH PERSON IS THE YOUNGEST ONE

22. Accept any city from the user and display monument of that
city.
City Monument
Delhi Red Fort
Agra Taj Mahal
Jaipur Jal Mahal

ANS PROBRAM
. a = input("Enter the city : ")
if a=="DELHI" or a=="delhi":
print("Monument of Delhi is 'Red Fort'")
if a=="AGRA" or a=="agra":
print("Monument of Agra is 'Taj Mahal'")
elif a=="JAIPUR" or a=="jaipur":
print("Monument of Jaipur is 'Jal Mahal'")
else:
print(" enter appropriate data")
OUTPUT
Enter the city : jaipur
Monument of Jaipur is 'Jal Mahal'

23. Write a program to accept percentage from the user and


display the grade according to the
following criteria:
Marks Grade
>90 A
> 80 and <= 90 B
>= 60 and <= 80 C
below 60 D

ANS PROBRAM
. a=int(input("enter your percentage = "))
if a<60:
print(" YOUR GRADE IS 'D' ")
elif 60<=a<=80:
print(" YOUR GRADE IS 'C' ")
elif 80<a<=90:
print(" YOUR GRADE IS 'B' ")
elif 90<a:
print(" YOUR GRADE IS 'A' ")
else:
print(" ENTER APPROPRIATE PERCENTAGE")
OUTPUT
enter your percentage = 94
YOUR GRADE IS 'A'

24. Write a program to accept the cost price of a bike and display
the road tax to be paid according to the following criteria:
Cost price (in Rs) Tax
> 100000 15%
> 50000 and <= 100000 10%
<= 50000 5%

ANS PROBRAM
. a=int(input("enter the cost price of a bike = "))
if a>100000:
print(" THE ROAD TAX TO BE PAID IS ",15/100*a)
elif 50000<a<=100000:
print(" THE ROAD TAX TO BE PAID IS ",10/100*a)
elif a<=50000:
print(" THE ROAD TAX TO BE PAID IS ",5/100*a)
else:
print(" ENTER APPROPRIATE PERCENTAGE")
OUTPUT
enter the cost price of a bike = 1000000
THE ROAD TAX TO BE PAID IS 150000.0

25. Find the lowest number out of two numbers excepted from
user

ANS PROBRAM
. a=float(input("enter the first number = "))
b=float(input("enter the second number = "))
if a>b:
print(" THE LOWEST OUT OF THE TWO NUMBER IS
",b)
elif a<b:
print(" THE LOWEST OUT OF THE TWO NUMBER IS
",a)
elif a==b:
print(" THE BOTH NUMBER ARE EQUAL ")
else:
print(" ENTER APPROPRIATE NUMBER ")
OUTPUT
enter the first number = 100.1
enter the second number = 1001
THE LOWEST OUT OF THE TWO NUMBER IS 100.1

26. To check whether a number (accepted from user) is divisible


by 2 and 3 both

ANS PROBRAM
. a=float(input("enter the first number = "))
if a%6==0:
print(" YES, THE NUMBER ENTERED IS DIVISIBLE BY
BOTH 2 AND 3 ")

else:
print(" NO, THE NUMBER ENTERED IS NOT DIVISIBLE
BY BOTH 2 AND 3 ")
OUTPUT
enter the first number = 66
YES, THE NUMBER ENTERED IS DIVISIBLE BY BOTH 2
AND 3

27. To find the largest number out of three numbers excepted


from user.

ANS PROBRAM
. a=float(input("enter the first number = "))
b=float(input("enter the second number = "))
c=float(input("enter the third number = "))
if a>b and a>c :
print(" THE LARGEST OUT OF THE THREE NUMBER IS
",a)
elif b>a and b>c:
print(" THE LARGEST OUT OF THE THREE NUMBER IS
",b)
elif c>a and c>b:
print(" THE LARGEST OUT OF THE THREE NUMBER IS
",c)
elif a==b==c:
print(" ALL NUMBER ARE EQUAL ")
else:
print(" ENTER APPROPRIATE NUMBER ")
OUTPUT
enter the first number = 23
enter the second number = 24
enter the third number = 25
THE LARGEST OUT OF THE THREE NUMBER IS 25.0

28. Input side of quadrilaterals and check it is square or rectangle

ANS PROBRAM
. a=float(input("enter the first side = "))
b=float(input("enter the second side = "))
c=float(input("enter the third side = "))
d=float(input("enter the forth side = "))
if a==b==c==d :
print(" THE QUADRILATERAL IS A SQUARE ")
elif b==d and c==a:
print(" THE QUADRILATERAL IS A RECTANGLE ")
else:
print(" ENTER APPROPRIATE DATA ")
OUTPUT
enter the first side = 15
enter the second side = 36
enter the third side = 15
enter the forth side = 36
THE QUADRILATERAL IS A RECTANGLE

29. Input two angle from the user and find the third one if
possible else print wrong input

ANS PROBRAM
. a=float(input("enter the first angle = "))
b=float(input("enter the second angle = "))
if a<180 and b<180:
if a<90 and b<90:
print(" THE THIRD ANGLE IS ",180-(a+b))
elif a>90 and b>90:
print("WRONG INPUT")
elif a>90 and b<90:
print("THE THIRD ANGLE IS ",180-(a+b))
elif a<90 and b>90:
print("THE THIRD ANGLE IS ",180-(a+b))
else:
print(" WRONG INPUT ")
OUTPUT
enter the first angle = 90
enter the second angle = 45
THE THIRD ANGLE IS 45.0

30. Write a program to check if the number is buzz nos or not


(BUZZ nos are numbers which are divisible by 7 or end with
7)

ANS PROBRAM
. a=int(input("enter any number = "))
if a%10==7 or a%7==0:
print(" IT IS A BUZZ NUMBER ")
else:
print(" IT IS A BUZZ NUMBER ")

OUTPUT
enter any number = 17
IT IS A BUZZ NUMBER

You might also like