Question: Pyhton please! 2 9 . 2 0 LAB: Swap two numbers Complete the swap ( ) method to exchange the values of the num attribute

Pyhton please! 29.20 LAB: Swap two numbers
Complete the swap() method to exchange the values of the num attribute of two Number objects, num1 and num2.
Hint: Refer to the given Number class to see the definitions of num attribute and other instance methods available.
Ex: If num1 is 19 and num2 is 178, calling swap(num1, num2) will swap the values so that num1 becomes 178 and num2 becomes 19.
class Number:
def __init__(self, n):
self.num = n
def get_num(self):
return self.num
def set_num(self, n):
self.num = n
def swap(num1, num2):
num1.num = self.num
num2.num = num1.num
num1.num = num2.num
if __name__=="__main__":
int1= int(input())
int2= int(input())
num1= Number(int1)
num2= Number(int2)
swap(num1, num2)
print('num1=',num1.get_num(),'and num2=',num2.get_num())

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!