0% found this document useful (0 votes)
12 views

Week6 (Python Lab)

Hooooalo

Uploaded by

abhinavicon789
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Week6 (Python Lab)

Hooooalo

Uploaded by

abhinavicon789
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Week-6

1. Write a python program to perform bitwise operations on


two numbers?
a=int(input(“Enter a value :”))
b= int(input(“Enter b value :”))
print(‘Bitwise AND :’, a & b)
print(‘Bitwise OR :’, a | b)
print(‘Bitwise XOR :’, a ^ b
print(‘Bitwise Compliment :’, ~a)
print(‘Bitwise Left shift :’, a << 2)
print(‘Bitwise Right shift :’, a >> 2)

Output:
Enter a value : 6
b value : 3
Bitwise AND : 2
Bitwise OR : 6
Bitwise XOR : 4
Bitwise Compliment : -7
Bitwise Left shift : 24
Bitwise Right shift : 1
2. Write a Python program to precedence of operators in
expression evaluation?
x = 12
y = 14
z = 16
result_1 = x + y * z
print("Result of 'x + y + z' is: ", result_1)
result_2 = (x + y) * z
print("Result of '(x + y) * z' is: ", result_2)
result_3 = x + (y * z)
print("Result of 'x + (y * z)' is: ", result_3)
output:
Result of 'x + y + z' is: 236
Result of '(x + y) * z' is: 416
Result of 'x + (y * z)' is: 236
3. Write a Python program to check whether given key exists
in a dictionary or not. If found, retrieve the value,
otherwise add given key and a value to dictionary.
dic={"name":"ram","age":20}
print(dic)
key=input("enter key")
if key in dic:
print(key,"is present")
print("value is:",dic[key])
else:
print(key,"is not present")
x=int(input("enter value:"))
dic.update({key:x})
print(dic)
output:
{'name': 'ram', 'age': 20}
enter key salary
salary is not present
enter value:50000
{'name': 'ram', 'age': 20, ' salary': 50000}
Output-2
{'name': 'ram', 'age': 20}
enter keyname
name is present
value is: ram

You might also like