Circulate the values of n variables

# Circulate the values of n variables


no_of_terms = int(input("Enter number of values : "))

#Read values
list1 = []
for val in range(0,no_of_terms,1):
    ele = int(input("Enter integer : "))
    list1.append(ele)


#Circulate and display values
print("Circulating the elements of list ", list1)
   
for val in range(0,no_of_terms,1):
    ele = list1.pop(0)
    list1.append(ele)
    print(list1)

11 comments:

  1. Good Solution, Are there any alternate solutions to do a comparative study?

    ReplyDelete
  2. Alternative solutions
    Use a nested for loop and just print the values based on index. Don't actually disturb the list. Just the display based on index.

    Tried them both. But the pop, append and display was the most efficient.

    ReplyDelete
  3. I'm a beginner where I can learn Python well?

    ReplyDelete
    Replies
    1. for beginners - Think Python by Allen Downey, Green Tea Press is good

      Python Essential Reference by David Beazley for more advanced content and explanations

      Core Python Programming by Wesley J. Chun

      use online tutorials for more examples

      only way to learn a programming language is by doing programs
      practice all the assignment problems i have posted.
      all the best. happy programming

      Delete
  4. Madam I think last line print Statement should come after the loop.not inside the loop..

    ReplyDelete
    Replies
    1. execute the program and see.
      first element is removed and appended to the end position and all the values in the list are moved by one position.
      This repeats until they reach their original position.

      print statement is given inside the loop to display the element position each time they are moved.

      Delete
  5. circulate the value in two n variables-program,algorithm,
    flow chart,pseudo code,......

    ReplyDelete
  6. mam pls upload a algorithm for this program

    ReplyDelete
  7. It will be better with algorithms

    ReplyDelete

Don't be a silent reader...
Leave your comments...

Anu