Random: Python Challenge!

Hi there! Here’s a challenge you might be able to solve AND HELP ME:

We have a group of 6 people, out of whom we need to choose a leader and AN ASSISTANT. You should do it so that the LEADER AND the ASSISTANT cannot be the same person.

I somehow tried, I just went like this:

import random

members = ['Max', 'John', 'Elsa', 'Mike', 'Asiia', 'Mosh']

leader = random.choice(members)
assist = random.choice(members)
print(f'The leader is {leader} and assistant is {assist}')

However, this is not ACCURATE, I mean the LEADER and ASSISTANT might be the same person according to this logic. What I would like to see is that if there’s a person named Max chosen to be the leader of the group, AND he cannot be an assistant as well. The code has to choose someone else.

stop this shit n do ur work

1 Like

karu, this sh*t is MY work.

Thank you, I have learnt a lot of things due to this question that I’d come with earlier.

I think this is the answer, you might have different codes tho’:

  1. I got a leader
  2. Once the leader’s chosen, I removed him/her from the members
  3. And got the assistant:
import random
members = ['Max', 'John', 'Elsa', 'Mike']
leader = random.choice(members)

if leader:
    members.remove(leader)
    assist = random.choice(members)
    print(f'The leader is {leader} and assistant is {assist}')
1 Like

@uLN there’s a lot a website where you can improve your logic hackerrank, codechef, hackerearth, codestudio, and finally leetcode

1 Like