0% found this document useful (0 votes)
5 views5 pages

Logical Operator

The document outlines basic mathematical and logical operators in Python, including examples of their usage. It provides solutions to assignments that involve conditional statements and variable assignments. The content emphasizes correct syntax and indentation for Python code execution.

Uploaded by

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

Logical Operator

The document outlines basic mathematical and logical operators in Python, including examples of their usage. It provides solutions to assignments that involve conditional statements and variable assignments. The content emphasizes correct syntax and indentation for Python code execution.

Uploaded by

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

Mathematical operators

+
-
*
/

Logical operator
operator Keyboard Python
Equals = ==
Not Equals <> !=
less than < <
greater than > >
less than or <= <=
equals
greater than or >= >=
equals

AND operator (Both true)


if a>b and a>c :
print(‘Both are true, a is large’)
OR operator (Either)
if a >b or a>c:
print(‘At least one is true’)

Answers Assignment 2:
1. Print "Hello World" if a is not equal to b.

if a!=b:
print(‘Hello’)

2) Correct the indentation to make the code run


properly:
a=5
b=2
if b>a:
print("b is greater than a")
else:
print ("a is greater than b")
3) Print "Yes" if a is equal to b, otherwise print "No".
if a = b :
print(‘yes’)
else:
print(‘No’)

4) Print "1" if a is equal to b, print "2" if a is greater than


b, otherwise print "3".

if a = b:
print(‘1’)
elif a > b:
print(‘2’)
else:
print(‘3’)

5. ) Print "Hello" if a is equal to b, and c is equal to d.

if a == b and c == d:
print(‘Hello’)
6.) Print "Hello" if a is equal to b, or if c is equal to d.

if a ==b or c ==d:
print(‘Hello’)

Answers Assignment 1–

1. Assign the value Sri Lanka to a variable named


country.
country = (‘Sri Lanka’)
print(country)

2. Display the sum of 5 + 10, using two variables; x and


y.
x=5
y= 10
print(x+y)

3. Create a variable called z, assign x + y to it, and


display the result.
z = x+y
print(z)
4. Circle the error in the variable name;
1stName

5. Assign the same value “Beethoven” to all three


variables a, b, and c using one code line.

a=b=c=’Beethoven’
print(a)
print(b)
print(c)

You might also like