Week6 (Python Lab)
Week6 (Python Lab)
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