I would like to know why python is saying that I have provided 3 arguments in this function?

0

Code:

print("Jogo do chute...")

import random

numeroaleatorio = random.randrange(100)
chutes = 0
r = True

while r:
    chute = int(input("Digite um número de zero(0) a cem(100): "))
    if chute > numeroaleatorio:
        print("Número muito alto...")
        chutes +=1

    elif chute < numeroaleatorio:
        print("Número muito baixo...")
        chutes +=1

    elif chute == numeroaleatorio:
        print("Você acertou...\nA quantidade de chutes que você deu foram %i"%chutes)
        break

Error message:

Jogo do chute...
Traceback (most recent call last):
  File "y.py", line 41, in <module>
    numeroaleatorio = random.choice(1, 100)
TypeError: choice() takes 2 positional arguments but 3 were given

Given this why python is saying that I provided 3 arguments and that I only provided two arguments '1' and '100'?

    
asked by anonymous 05.07.2017 / 20:26

2 answers

3

In python 3 you should generate the random value you want this way:

randrange:

from random import randrange
rnd = randrange(1,100)

Output:

print(rnd)
92

Or:

choice:

from random import choice
rnd = choice(range(1,100))

Output:

print (rnd)  
61

Run the code on repl.it

    
05.07.2017 / 21:06
1

The purpose is to choose a number from 1 to 100?

You can use

random.randrange(1, 100);

//random.randrange([start], stop[, step])

or

random.choice(range(1, 100, 1))

//random.choice(range(start, stop, step))
    
05.07.2017 / 20:38