Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I tryed the slicing stuff in python, but something went wrong

+3 votes
asked Sep 19 by CodeKid (540 points)
Hi! can somebody check the code and tell me what's wrong? https://onlinegdb.com/_U1B8WPaZ .

i wanted the program to print the list backwards, 9 to 0. And there is no problem, it just wont print anything

1 Answer

+2 votes
answered Sep 19 by Peter Minarik (58,220 points)

To reverse a sequence, try the reversed operator to get the reverse iterator, then enumerate all the elements:

numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for element in reversed(numbers):
    print(element)

I did some research and this can be achieved via slicing as well:

numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for element in numbers[::-1]:
    print(element)

commented Sep 20 by CodeKid (540 points)
Now i found the website "learnpython.org", there was that slicing stuff. But I never knew'd about the "reversed" stuff. Thanks, again
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...