Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialdakota ferrell
2,336 Pointshow 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")
3 Answers
Steven Parker
231,236 PointsYou almost had it, you just need to add parentheses to call your function:
if user_number() == 2:
Steven Parker
231,236 PointsIt'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
2,336 Pointsim 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.
dakota ferrell
2,336 Pointsis there a way to use a if statement with a {}.format() method?
Steven Parker
231,236 PointsSure, but it doesn't look like you'd need that here. Or what did you have in mind?