I want to print String and number both from list randomly

Question:

import random

s=[1,2,3]

b={'AM','PM'}

c=random.shuffle(s,b)

print(c)

I want ot print both from random in python.

I want output like this: 1AM OR 3 PM`

Asked By: Nature Lover

||

Answers:

To my understanding what you are trying to achieve is a random time using the list and the set.

To do so you’ll have to choose one random element from list followed by one from the set.

Here is it the code which works, with minimal number of changes from your code.

import random

s=[1,2,3]

b={'AM','PM'}

c=str(random.choice(s))+random.choice(tuple(b))

print(c)

Hope this helps✌️

Answered By: Tushar Bansal
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.