Python Forum
Help with a random.randint choice in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a random.randint choice in Python
#5
I'd do it a bit differently, based more around code like this
import random
options = list()
options.append('First entry')
options.append('Second entry')
options.append('third entry')
options.append('fourth entry')
print(options[random.randint(0,len(options)-1)])
That does not limit you to 26 choices, and would be more maintainable.
booponion likes this post
Reply


Messages In This Thread
RE: Help with a random.randint choice in Python - by jefsummers - Oct-23-2020, 03:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 585 Nov-27-2023, 05:17 PM
Last Post: janeik
  Unexpected output while using random.randint with def terickson2367 1 536 Oct-24-2023, 05:56 AM
Last Post: buran
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,495 Sep-10-2023, 10:27 PM
Last Post: janeik
Sad Iterate randint() multiple times when calling a function Jake123 2 2,082 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  random.choice HELP samuelbachorik 4 2,293 Aug-18-2021, 03:24 PM
Last Post: naughtyCat
  Unable to use random.choice(list) in async method spacedog 4 3,482 Apr-29-2021, 04:08 PM
Last Post: spacedog
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,325 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  trying to input a variable using random.choice python63 9 3,673 Aug-13-2020, 05:37 PM
Last Post: python63
  Random Choice Operations Souls99 6 2,962 Jul-31-2020, 10:37 PM
Last Post: Souls99
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 11,760 May-31-2020, 03:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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