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
#4
You don't need parentheses around the string assignments.

I'd probably prefer to put the text into a container (like a list/dict/tuple) rather than into 26 top-level variables.

But the main problem is that random.choice takes a single sequence. You're feeding it 26 individual variables. Wrap them in another pair of parentheses to make a tuple and it should work.

print(random.choice((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z))
booponion likes this post
Reply


Messages In This Thread
RE: Help with a random.randint choice in Python - by bowlofred - 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 538 Oct-24-2023, 05:56 AM
Last Post: buran
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,517 Sep-10-2023, 10:27 PM
Last Post: janeik
Sad Iterate randint() multiple times when calling a function Jake123 2 2,094 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  random.choice HELP samuelbachorik 4 2,297 Aug-18-2021, 03:24 PM
Last Post: naughtyCat
  Unable to use random.choice(list) in async method spacedog 4 3,486 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,333 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  trying to input a variable using random.choice python63 9 3,683 Aug-13-2020, 05:37 PM
Last Post: python63
  Random Choice Operations Souls99 6 2,965 Jul-31-2020, 10:37 PM
Last Post: Souls99
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 11,769 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