doc_collage_python
doc_collage_python
temp = a
a=b
b = temp
return a, b
x=5
y = 10
print("Before swap:")
print("x =", x)
print("y =", y)
x, y = swap_variables(x, y)
print("After swap:")
print("x =", x)
print("y =", y)
Before swap:
x=5
y = 10
After swap:
x = 10
y=5
a=a+b
b=a-b
a=a-b
return a, b
x=5
y = 10
print("Before swap:")
print("x =", x)
print("y =", y)
x, y = swap_without_temp(x, y)
print("After swap:")
print("x =", x)
print("y =", y)
Before swap:
x=5
y = 10
After swap:
x = 10
y=5
4. Write a program to find out and display the common and the
non-common elements in the list using membership operators.
list1 = [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
a = 10
b = 10
if a is b:
print("a and b refer to the same object.")
else:
print("a and b refer to different objects.")
b = 20
if a is b:
print("a and b refer to the same object.")
else:
print("a and b refer to different objects.")
1 3 5 7 9 11 13 15 17 19 21 23 25
27 29
factorial = 1
Enter a number: 5
Factorial series up to 5:
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120
for i in range(n):
print(a, end=" ")
a, b = b, a + b
01123
Sum of digits: 12