To circulate the values

 

To circulate the values

To circulate the values of multiple variables n, you can shift their values in a circular manner. This means that the value of each variable will be assigned to the next variable, while the last variable's value will be assigned to the first variable


CODE:

# Number of variables n = 4 # Initial values values = [10, 20, 30, 40] # Example values # Circulate the values temp = values[n - 1] for i in range(n - 1, 0, -1): values[i] = values[i - 1] values[0] = temp # Print the circulated values for i in range(n): print(f"values[{i}] =", values[i])

OUTPUT:

values[0] = 40 values[1] = 10 values[2] = 20 values[3] = 30

Comments

Popular posts from this blog

ILLUSTRATIVE PROGRAMS IN PYTHON

Fibonacci Series

The Fibonacci series