0

Hi there

Im doing a project at the moment and need to find the numbers 1,2 and 3 i(all) in any order entered by the user.

A=[]
B=[0,1,2,3,4]
lengthOfList = int(input("Enter the number of elements:"))

for i in range(0,lengthOfList):
elm = int(input("Enter and element value: "))
A.append(elm)

print(A)

Code so far, just need help with the functions

Regards

Paul

4
Contributors
5
Replies
35
Views
11 Months
Discussion Span
Last Post by rproffitt
0

In psuedo code something like:
if 1 in B and 2 in B and 3 in B do something.

Looks like you need something like this one liner to test for that.

0

Thank for this code.

I have tried it and it nearly works, but if you do two of the three numbers, it returns a yes.

All need all three to be present.

Thank you

0

You could use

if all(x in A for x in (1, 2, 3)):

or

if set((1, 2, 3)).issubset(A):

or

if 3 == len(set(range(1, 4)) & set(A)):

Edited by Gribouillis

0

This smells like (not teen spirit) sets! Have a look on sets and Python and I guess your problems will be solved. Success!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.