1. Find the output :
year=int(input("enter any
year to be checked "))
if((year%4==0)and (year%100!=0) or (year%400==0)):
print("Leap year")
else:
print("Not a leap year")
2. Example program on All
Arithmetic Operators
3. Find out the output: (a) “sitha*2.5 (b) 10.2* “rajendra”
(c)>>>
a=5
>>>
a/0
4. Evaluate the following expression:
(a) d=(x+y)*z**a//b+c where
x=1;y=2;z=3;a=2;b=2;c=3 (Explain step by step procedure)
(b) Find out the output: “Ravi”+15
5. Define
the Relational operators
6. Find
out the output
a="ravi"
b="Ravi"
print(a>b)
print(a>=b)
print(a==b)
print(a!=b)
7.Write a
program for the Expected output: Using Relational Operators
False
False
True
True
False
8. What is
Chaining of Relational Operators?
9. What is the output:
(a) >>> a=10
>>> 5<a<20
(b) >>> a=10
>>> 10<a>20
10.
(a) Write a python
program for the following output:
rajendra
rajesh
Hyd
True
False
(b). Find out the
output for the following program
a=True
b=False
print(a and a)
print(a and b)
print(b and b)
print(a or a)
print(a or b)
print(b or b)
print(not a)
print(not b)
.
Key:
1.
Error
2. Example program on all arithmetic operators
a=10 #
value 10 is stored in variable a
b=2 #
value 2 is stored in variable b
print('a+b=',a+b)
#Addition operator
print('a-b=',a-b)#Subtraction
operator
print('a*b=',a*b)#Multiplication
print('a/b=',a/b)#Division
operator
print('a//b=',a//b)#Floor
Division (integer Division)
print('a%b=',a%b)#Modulus
operator Which gives remainder
print('a**b=',a**b)#Exponenet
operator
"""output
a+b= 12
a-b= 8
a*b= 20
a/b=
5.0
a//b= 5
a%b= 0
a**b=
100
3. Find out the output:
(a)
“sitha*2.5 # Error
Explanation:
If we use * operator for strings then we must use one parameter should be
integer and other parameter should be string type
(b)
10.2* “rajendra” #Error , explanation
same as above
(c) >>>
a=5
>>>
a/0 # Error Division by Zero we can not perform in programming language
4. (a)
>>>
d=(1+2)*3**2//2+3
d=3*3**2//2+3
#parenthesis evaluated
d=3*9//2+3
#Exponential operator is evaluated
d=27//2+3
#Multiplication, division, and floor divisions are at equal priority
d=13+3
#addition and subtraction are afterwards
d=16
#finally assignment is performed, the value is 16 now stored in variable ‘d’
>>>
print(d)
16
>>>
(b.) Find out the output: “Ravi”+15 # Error right one is: “Ravi”+’15’
5.
Relational Operators compares two operands and returns true or false (1 or 0).
We can understand whether
two values are same or bigger or smaller, using these operators.
6. Find out the output
a="ravi"
b="Ravi"
print(a>b)
print(a>=b)
print(a==b)
print(a!=b)
Output:
True
True
False
True
7.
Write a
program for the Expected output:
a>b #False
a>=b #False
a<b #True
a<=b #True
a==b #False
output:
False
False
True
True
False
8. output
True
True
False
True
""""
Python
string comparison is performed using the characters in both strings. The
characters in both strings are compared one by one. When different characters
are found then their Unicode value is compared. The character with lower
Unicode value is considered to be smaller.
9. What is the output:
(a)>>> a=10
>>> 5<a<20
True
>>>
Here, 5
is less than 10 i.e 5<a so True, and then 10 is less than 20 i.e a<20 so
True. Since both the conditions are True, Hence Result is True
(b) >>> a=10
>>> 10<a>20
False
>>>
Here 5 is greater than or equal to 10 is False.
But 10 is less than 20 is True. Since we get false and True, the result will be
false.
5>=aà5>=10àFalse
a<20à10<20àTrue
False and True so the result is False
10.
(a) Write a python
program for the following output:
rajendra
rajesh
Hyd
True
False
Ans:
print("ravi" and
"rajendra") # In and operator :1st argument is True so returns 2nd argument i.e rajendra
print("" and "Sitha")
#In and operator :1st argument is False so returns 1st argu: #empty
string
print("kiran" and "")#1st argument is True so returns 2nd argument i.e empty (false) i.e empty
print("" or "rajesh) #in OR operator: 1st is False so returns 2nd i.e #rajesh
print("Hyd" or "") #in OR operator: 1st True so returns 1st “Hyd
print(not "") # not False i.e True
print(not "Vij") #not True i.e False
(b). Find out the
output for the following program
a=True
b=False
print(a and a)
print(a and b)
print(b and b)
print(a or a)
print(a or b)
print(b or b)
print(not a)
print(not b)
Ans:
output
True
False
False
True
True
False
False
True
All the assignments: Assessments
No comments:
Post a Comment