Python Introducing Lists Build an Application Wrap Up

dakota ferrell
dakota ferrell
1,454 Points

how can I get this code to work?

l1 = ([1, 2, 3, 1, 2, 3])

l3 = set(l1)

l2 = list(set(l1)) l4 = list(l3) print(l1, l2, l3, l4)

def user_number (num): user_num = input ("whats your number?") num = user_num return user_num

number = print(user_number(1))

if user_number == 2: print("found")

2 Answers

Steven Parker
Steven Parker
181,132 Points

It's hard to read Python without Markdown formatting, and it's not clear what the program is intended to do. But one thing that stands out even now is that "user_number" is defined as a function but then later compared it with the number "2" as if it was a variable.

Also, "print" doesn't return anything so it's not useful to assign to the variable "number" (which is then not used anyway).

dakota ferrell
dakota ferrell
1,454 Points

im really just trying to think of away to get a if to print out a message to a certain number even though the number might change for instance the user inserts the number 1 then the if stament runs and they get a message but what if user2 uses the number 2 I want them to get the same message. I know there are better ways of doing this but I was wondering if I can make a if stament to run without knowing what the value is at a given point.

Steven Parker
Steven Parker
181,132 Points

You almost had it, you just need to add parentheses to call your function:

if user_number() == 2:
dakota ferrell
dakota ferrell
1,454 Points

is there a way to use a if statement with a {}.format() method?

Steven Parker
Steven Parker
181,132 Points

Sure, but it doesn't look like you'd need that here. Or what did you have in mind?