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

Python Programmes Unit 1

Uploaded by

ravalichandra414
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 views4 pages

Python Programmes Unit 1

Uploaded by

ravalichandra414
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/ 4

Python programmes

UNIT I

1.Find the Largest Element Among Three Numbers

num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

num3 = int(input("Enter third number: "))

largest = max(num1, num2, num3)

print("The largest number is:", largest)

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

num3 = float(input("Enter third number: "))

if num1 >= num2 and num1 >= num3:

largest = num1

elif num2 >= num1 and num2 >= num3:

largest = num2

else:

largest = num3

print("The largest number is:", largest)

2. Display All Prime Numbers Within an Interval

start = int(input("Enter the starting number of the interval: "))

end = int(input("Enter the ending number of the interval: "))

print(f"Prime numbers between {start} and {end} are:")for num in range(start, end + 1):

if num > 1:

for i in range(2, int(num ** 0.5) + 1):

if num % i == 0:

break

else:
print(num, end=" ")

3. Swap Two Numbers Without Using a Temporary Variable

a = int(input("Enter the first number: "))

b = int(input("Enter the second number: "))

# Swapping

a, b = b, a

print("After swapping, first number is:", a)

print("After swapping, second number is:", b)

4. Demonstration of Various Operators

a = 10

b=5

print("Arithmetic Operators:")

print("Addition:", a + b)

print("Subtraction:", a - b)print("Multiplication:", a * b)

print("Division:", a / b)

print("Modulus:", a % b)

print("Exponent:", a ** b)

print("Floor Division:", a // b)

# ii) Relational Operators

print("\nRelational Operators:")

print("a > b:", a > b)

print("a < b:", a < b)

print("a == b:", a == b)

print("a != b:", a != b)

# iii) Assignment Operators

print("\nAssignment Operators:")

c=a
print("c = a:", c)

c += b

print("c += b:", c)

c *= b

print("c *= b:", c)

# iv) Logical Operators

print("\nLogical Operators:")

print("a > 5 and b < 10:", a > 5 and b < 10)

print("a > 15 or b < 10:", a > 15 or b < 10)

print("not (a > 15):", not (a > 15))

# v) Bitwise Operators

print("\nBitwise Operators:")

print("a & b:", a & b)

print("a | b:", a | b)

print("a ^ b:", a ^ b)

print("~a:", ~a)

print("a << 1:", a << 1)

print("a >> 1:", a >> 1)

# vi) Ternary Operator

printt("\nTernary Operator:")

result = "a is greater" if a > b else "b is greater"

print("Ternary result:", result)

# vii) Membership Operators

print("\nMembership Operators:")

lst = [1, 2, 3, 4, 5]

print("2 in list:", 2 in lst)

print("6 not in list:", 6 not in lst)

# viii) Identity Operators


print("\nIdentity Operators:")

x=5

y=5

print("x is y:", x is y)

y=6

print("x is not y:", x is not y)

5. Add and Multiply Complex Numbers

num1 = complex(input("Enter the first complex number (in the form x+yj): "))

num2 = complex(input("Enter the second complex number (in the form x+yj): "))

# Perform addition and multiplication

sum_result = num1 + num2

product_result = num1 * num2

print("Sum of complex numbers:", sum_result)

print("Product of complex numbers:", product_result)

6. Print Multiplication Table of a Given Number

num = int(input("Enter a number for the multiplication table: "))

print(f"Multiplication table for {num}:")

# Generate the multiplication table

for i in range(1, 11):

print(f"{num} x {i} = {num * i}")

You might also like