HERE, N1 AND N2 I HAVE TAKEN AS A VARIABLE ,TO TAKE INPUT FROM THE USERS,AND IN THE 4TH LINE I HAVE ASSIGNED THE INTERCHANGED VALUE SO THAT THE VALUES IS SWAPPED AND N1 WILL BECOME N2 AND N2 WILL BECOME N1.
n2=int(input("ENTER NUMBER 2 : "))
print("ORIGINAL NUMBERS : ",n1,n2)
n1,n2=n2,n1
print("AFTER SWAPING : ",n1,n2)
HERE, I HAVE WRITTEN COMMAND USING INPUT FUNCTION TO TAKE VALUES FROM THE USER.NOW FIRST I WILL PRINT THE ORIGINAL NUMBERS IN THE SEQUENCE . AFTER THAT I HAD ASSIGNED THE VALUES TO SWAP THEM WHICH WAS GIVEN THE QUESTION OF SWAP ORDER. NOW I HAVE PRINTED THEM AFTER SWAPING FROM THE LAST COMMAND.
HERE, AS U CAN SEE,,
X(1ST NUMBER)=Y(2ND NUMBER)
Y(2ND NUMBER)=Z(3RD NUMBER)
Z(3RD NUMBER)=X(1ST NUMBER)
TRY IT YOURSELF !! : -
x=int(input("ENTER NUMBER 1 : "))y=int(input("ENTER NUMBER 2 : "))
z=int(input("ENTER NUMBER 2 : "))
print("ORIGINAL NUMBERS : ",x ,y ,z)
x ,y ,z=y ,z ,x
print("AFTER SWAPING : ",x ,y ,z)
PRACTICE QUESTION:
TELL ME THE ANSWER OF THIS IN THE COMMENTS SECTION !!!
TELL ME THE OUTPUT FOR THE FOLLOWING CODE: n1,n2=5,7 n3=n1+n2 n4=n4+2 print(n1,n2,n3,n4)
👍👀
No comments:
Post a Comment