Lab Assignment 5 Operators
Lab Assignment 5 Operators
Lab Assignment-05
Operators, Precedence of Operators and Tuple assignment
Q1 Write a Python program to compute and display the results of following expressions:
result1 = 10 + 5 * 2
result2 = (10 + 5) * 2
result3 = 100 / 5 + 2 * 3
result4 = 100 / (5 + 2) * 3
result5 = 2 ** 3 * 4
result6 = 2 ** (3 * 4)
result7 = 10 > 5 and 3 < 2 or 8 == 8
Q2 Hamming distance measures the number of positions at which the corresponding bits of two
binary numbers are different. Find Hamming distance between two binary numbers. Take two
integer numbers as input from the user and use bin() function to convert in binary.
Q3 Compare two binary numbers for greater than, less than, and equality comparison using lists.
Q4 Create a dynamic list by taking duplicate inputs from the user and then remove duplicates
from the list using membership operators in and not in.
Q5 a is 20, b is 7, c is 3.0 and d is [10, 20, 30, 40]. Compute the output of the given expression:
result = ((a + b * c) // 4 - 2) ** 2 >= 10 and (a + b - c) in d.
Q6 Write a Python program that takes two strings as input from the user and compares them
using different comparison operators (==, !=, <, >, <=, >=). The program should:
1. Check if both strings are equal.
2. Check if the strings are different.
3. Compare which string is lexicographically greater.
4. Compare which string is lexicographically smaller.
5. Handle cases where the strings have different capitalizations (use .lower()).
Q7 Write a Python program that demonstrates tuple assignment. The program should:
1. Take multiple values as input from the user (comma-separated).
2. Store these values in a tuple (use split() function).
3. Use tuple unpacking to assign the values to individual variables.
4. Print each variable separately