Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with randint/random
#1
I'm trying to learn how to do the randint function by searching online but when I ever I try using what websites say, I get an error message and I want to understand what I'm doing wrong. This is what I copied from websites and get an error with:
import random

print random.randint(0,5)
Am I missing something? Any help would be appreciated, thanks in advance.
Reply
#2
You need to include the error message when you get one.

I'm guessing it's because you're using Python 2 examples when you have Python 3 installed. You need to use parenthesis with print, like so:
print(random.randint(0,5))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 526 Nov-27-2023, 05:17 PM
Last Post: janeik
  Unexpected output while using random.randint with def terickson2367 1 469 Oct-24-2023, 05:56 AM
Last Post: buran
Sad Iterate randint() multiple times when calling a function Jake123 2 1,979 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,199 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  Help with a random.randint choice in Python booponion 5 2,712 Oct-23-2020, 05:13 PM
Last Post: deanhystad
  Inheriting, given number from randint is not working beLIEve 0 1,489 Oct-12-2019, 06:50 PM
Last Post: beLIEve
  same number everytime when using random.randint summeringpainting 5 8,092 Aug-23-2019, 11:01 AM
Last Post: Malt
  randint stops changing values in a loop Naito 4 3,277 Jan-30-2019, 08:15 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020