0% found this document useful (0 votes)
2 views3 pages

Python Operators Assignment Detailed

The document contains a series of Python programming assignments focused on various operators, including arithmetic, comparison, assignment, membership, identity, bitwise, and logical operators. Each question includes a program example, user input, and expected output. The assignments also cover concepts such as eligibility checks, even/odd determination, number swapping, and comparisons among multiple numbers.

Uploaded by

adya.pushp
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)
2 views3 pages

Python Operators Assignment Detailed

The document contains a series of Python programming assignments focused on various operators, including arithmetic, comparison, assignment, membership, identity, bitwise, and logical operators. Each question includes a program example, user input, and expected output. The assignments also cover concepts such as eligibility checks, even/odd determination, number swapping, and comparisons among multiple numbers.

Uploaded by

adya.pushp
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

Python Programming Assignment - Operators

Question: 1. Write a Python program to input two numbers and


display their Sum, Difference, Product, Quotient, Remainder, and
Exponentiation.

Program:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Sum =", a + b)
print("Difference =", a - b)
print("Product =", a * b)
print("Quotient =", a / b)
print("Remainder =", a % b)
print("Exponentiation =", a ** b)

Output:
Enter first number: 10
Enter second number: 3
Sum = 13
Difference = 7
Product = 30
Quotient = 3.3333333333333335
Remainder = 1
Exponentiation = 1000

Question: 2. Compare two numbers.

Program:
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
print("First number is greater than second:",a>b)
print("First number is less than or equal to second:",a<=b)
print("Both numbers are equal:",a==b)

Output:
Enter first number: 8
Enter second number: 5
First number is greater than second: True
First number is less than or equal to second: False
Both numbers are equal: False

Question: 3. Demonstrate assignment operators.

Program:
x=20
print("Initial Value =",x)
x+=5
print("After += 5 :",x)
x-=3
print("After -= 3 :",x)
x*=2
print("After *= 2 :",x)
x/=4
print("After /= 4 :",x)
Output:
Initial Value = 20
After += 5 : 25
After -= 3 : 22
After *= 2 : 44
After /= 4 : 11.0

Question: 4. Eligibility for Exam.

Program:
marks=int(input("Enter marks: "))
attendance=int(input("Enter attendance percentage: "))
if marks>=40 and attendance>=75:
print("Eligible for Exam")
else:
print("Not Eligible")

Output:
Enter marks: 75
Enter attendance percentage: 80
Eligible for Exam

Question: 5. Membership operator.

Program:
text="Artificial Intelligence"
ch=input("Enter a character: ")
if ch in text:
print("Character is present.")
else:
print("Character is not present.")

Output:
Enter a character: A
Character is present.

Question: 6. Identity operators.

Program:
list1=[1,2,3,4]
list2=[1,2,3,4]
print("list1 is list2 :",list1 is list2)
print("list1 is not list2 :",list1 is not list2)

Output:
list1 is list2 : False
list1 is not list2 : True

Question: 7. Bitwise operators.

Program:
a=int(input("Enter first integer: "))
b=int(input("Enter second integer: "))
print("Bitwise AND =",a&b)
print("Bitwise OR =",a|b)
print("Bitwise XOR =",a^b)

Output:
Enter first integer: 6
Enter second integer: 3
Bitwise AND = 2
Bitwise OR = 7
Bitwise XOR = 5

Question: 8. Even or Odd.

Program:
num=int(input("Enter a number: "))
if num%2==0:
print("Even Number")
else:
print("Odd Number")

Output:
Enter a number: 14
Even Number

Question: 9. Swap two numbers.

Program:
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
a,b=b,a
print("After swapping:")
print("First number =",a)
print("Second number =",b)

Output:
Enter first number: 10
Enter second number: 20
After swapping:
First number = 20
Second number = 10

Question: 10. First number greater than both.

Program:
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
if a>b and a>c:
print("First number is greater than both second and third numbers.")
else:
print("First number is not greater than both second and third numbers.")

Output:
Enter first number: 15
Enter second number: 10
Enter third number: 12
First number is greater than both second and third numbers.

You might also like