 Helpp | Sololearn: Learn to code for FREE!

0

Helpp

I have a case where I have a list called "bil" where it contains random numbers, the number of components of that number as much as the user requests. *For example, the user enters the number of components as many as 3, then fill the list as much as 3. bil = [3,9,20] Then I had to reverse the order of the "bil" list. I'm still new to python so i don't know how to solve it How do I solve this case?

+10

Glenn , here are some hints: (1) from random module we can use the choices method. this allow us to get k numbers out of a range (2) input how many numbers should be generated (3) use choices with a range from 0 upto 51, and get 3 random numbers as a list. [::-1] reverses the list: res = choices(range(0,51),k=num_inp) # num_inp contains the number of list elementes that should be generated

+3

Hint: 1.) import random and receive input data and convert to an integer 2.) initialize/ declare your list 3.) generate random nambers in a loop as many times as your input numbers an add in this list. Next time please link your attempt with a question.

+2

Reversing part: You can use reverse() or [::-1] https://www.programiz.com/python-programming/methods/list/reverse To understand why [::-1] reverses your list you can read here about list slices: https://stackoverflow.com/questions/509211/understanding-slice-notation

+2

Okay everybody, thanks for helping me🙏

+1

num=int(input()) bil=[3, 9, 20] print(bil[num])

+1

JaScript how i make a random number ?

+1

Glenn The first example shows you how to use the modul random https://www.sololearn.com/learn/Python/2438/?ref=app

+1

+1

import random user_input = int(input()) runs = 0 bil = [] while runs != user_input: bil.append(random.randint(0, 100)) runs += 1 reversed_bil = bil[::-1] print(reversed_bil)

+1

You can use functions and methods, in this specific case, use: list.reverse()

0

To get random numbers in python first u need import the random module.... Then use a while loop to get the desired amount of numbers...... This is exactly what this code does... import random bil = [] user = int(input()) m = 0 while True: bil.append(random.randint(0,999)) m += 1 if m == user: print(bil) break

0

Esteban Torres Aráuz. oh, yeah, I forgot about that