Write a program that swaps the values of three variables x, y, and z, so that x gets the value
of y, y gets the value of z, and z gets the value of x.
# initialize the values of x, y, and z
x = 1
y = 2
z = 3
# swap the values using a temporary variable
temp = x
x = y
y = z
z = temp
# print the new values of x, y, and z
print(f"x: {x}")
print(f"y: {y}")
print(f"z: {z}")
This program first initializes the values of x, y, and z. It then swaps the values using a temporary variable temp. Finally, it prints the new values of x, y, and z.
If you run the program, it will swap the values of x, y, and z and print the new values. For example, you might see something like:
x: 2
y: 3
z: 1
This means that the values of x, y, and z have been swapped, and x now has the value of y, y now has the value of z, and z now has the value of x.

0 Comments