Bot Watches You
Bot Watches You

Reputation: 1

Why does the choice attribute (python) not work?

I have been trying to build a randomized greeting program, so far I got:

import random
a = ("Hi!", "How are you?", "You Good?")
b = random.choice(a)
print(b)

It used to work, but now it just says that there are no attributes for .choice, can someone help?

Edit1: I think my Python is broken...

Edit2: Wait it's fixed now...

Upvotes: 0

Views: 53

Answers (2)

kartik tyagi
kartik tyagi

Reputation: 7150

Your code is correct. Here are some step to refine or rebuild you code:

  1. Rename the file and try again.
  2. In random.choice(a). 'a' should be a List, Tuple, or String only.
  3. try with square brackets [] instead of small bracket (). Like a = ["Hi!", "How are you?", "You Good?"]
  4. Update your Python with the latest version.

Upvotes: 0

Tiger-222
Tiger-222

Reputation: 7150

Rename your own script to something different than random.py.

Upvotes: 1

Related Questions