Python random module, here's a question!

Asked 2 years ago, Updated 2 years ago, 16 views

I'm going to use a=random.uniform (0,10) to generate a random number.

You have to repeatedly generate different random numbers each time, and then re-enter random.uniform(0,10) each time

I only know how to give it to them ㅠ<

In the case of C language, I heard that there is a command that changes the value every time you type a

I'd appreciate it if you could tell me what Python is ㅠ<

python

2022-09-22 20:21

1 Answers

You just have to write a repeat sentence. Learn Python lectures on repeat sentences at Programmers Python lectures.

import random
while True:
    if input() == 'a':
            a = random.uniform(0,10)
    else:
            break

In the example above, each time you enter a on the keyboard, you assign a new random number to the variable a, and if you do not enter a on the keyboard, the program will exit.


2022-09-22 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.