What's new

JayNeiL

Honorary Poster
Established
Joined
Jun 25, 2016
Posts
328
Reaction
219
Points
235
pa help po
3. Create a Python program using Tuple Assignment that reverse the following given
numbers from highest to lowest.
Given: [1,2,3,4,5,6,7,8,9,10]
 
Here's a Python program that uses tuple assignment to reverse the given list of numbers from highest to lowest:

Python:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# using tuple assignment to reverse the list
numbers = tuple(numbers)
numbers = numbers[::-1]
numbers = list(numbers)

print("Reversed numbers:", numbers)

Output:

Code:
Reversed numbers: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

In the code above, we first define the list of numbers. Then, we convert the list to a tuple using the tuple() function, and use tuple assignment to reverse the order of the elements in the tuple using the slicing operator [::-1]. Finally, we convert the tuple back to a list using the list() function and print the reversed list.
 
Back
Top