Have a question as a newbie to Python?

There's a list function. I've also created one in Python with different numbers in a row. My goal is to generate multiple random numbers, which already works, and the value of the generated two-digit number that is at the end of the list, compared to the other generated numbers, wins. How do I do that?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
2 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
jo135
7 months ago

Lists are not a function, but a data type. Your question is difficult to understand without at least one, two lines of code.

The last (“sinterest”) item of a list you will get

liste[-1]

out. List indices may also be negative in Python, then counted from the rear to the front.

cleanercode
7 months ago

My goal is to generate several random numbers, which already works and the value of the generated two manipulated numbers , which is in the rearmost place in the list, unlike the other generated numbers , wins.

First you have to sort the list:

scores = [ 1, 4, 85, 3, 22, 88, 5, 10 ]

scores.sort()

Now the list is sorted.

On the last value of a list, you’ll get over

scores[-1] # idiomatischer Ansatz
# oder
scores[len(scores) - 1:]) # naja-Ansatz

too.