0
Help.
Randint doesn’t work and random won’t really work. Please help. Code: https://code.sololearn.com/cIsZ1Zc684jl/?ref=app
5 Respostas
+ 2
import random
def game(max_int, min_int):
number = random.randint(min_int, max_int)
guess = input()
if guess == number:
print("u win")
else:
print("wrong")
game(10, 1)
I try to correct your code and now it gives no error
+ 11
there is one issue with both of the codes shown here. the input is taken as a string, and then compared against an integer value that is generated by the randint() function.
this means: if the random number is 7 and the input number is '7', we can not get True when using: if guess == number:
to avoid this, the input should be:
guess = int(input())
+ 5
https://code.sololearn.com/c9gwMY12HzUd/?ref=app
It also works...as Lothar said int(input ()) is the correct format...
+ 3
randint is a function inside random module. You need to use the 'from' keyword to import the 'randint' function
> from random import randint
Syntax:
<from 'module_name' import 'function'>
or you can also import the random module and use the .(dot) notation to access the randint function
> import random
> random.randint() # any logic
+ 2
First, a vital hint when asking programming related questions: always be precise. Never use "doesn't work", always describe what happens - the exact error message, the expected and actual outputs, etc.
That said, the error message says the interpreter can't find the included module. Double check the module name.
Maybe it helps to notice you spelled this name differently in the code and the question.
Also important to check if SoloLearn's interpreter supports this module. An easy check is to run the same code in the original Python shell.