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 trial

Python

I'm a Beginner and my simple code won't work

This is my code:

print("Choose something you like to do to find the perfect match...\n\n")
block = print(input(" 1 = is not a smoker, 2 = is smoker, 3 = likes eating, 4 = likes fishing, 5 = likes sweets.\n\n Type what number you want but only choose one: "))

megan = "is not a smoker"
darel = "is smoker"
martha = "Likes sweets"
quess = "likes eating"
daisy = "likes to fish"

print(block)

if block == 1:
    print("Megan is your perfect match")
elif block == 2:
    print("Darel is your perfect match")
elif block == 3:
    print("Quess is your perfect match")
elif block == 4:
    print("Daisy is your perfect match")
elif block == 5:
    print("Daisy is your perfect match")
else:
    print("Were sorry, but their is no pefect match for you")

I see multiple errors here, however Reading thru unformatted code like this is tidies.

Below the "add an answer" area you'll see a "markdown cheatsheet" that will show you how to for,at code properly. Please repost your formatted code, and ill be sure to take a look.

4 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Caleb;

Great work on your script here. It isn't working as intended for a couple of reasons.

1) When you do a print(input()) statement you don't get the input object that you are really thinking about. If you add in a print(type(block)) statement after your print(block), you'll see that it is of type None. If you remove that print() call in line 2, that will help.
2) After removing that print call, you are still getting the information back as a string. You then try to compare it to integer values. As such, you will always make it to the else: statement because the string of "1" isn't going to be equal to the int value 1. If that makes sense.

There's a couple of ways to resolve issue 2.

First, you can convert all of the checks to strings, for example if block == '1'. Works, but isn't ideal.
Second, and better in my opinion, would be to convert block to an int value. You can do this when you assign the variable.

block = int(input("Your text here"))

Then your code will work as I think you are intending it to.

Happy coding,
Ken

print("Choose something you like to do to find the perfect match...\n\n")

block = print(int(input(" 1 = is not a smoker, 2 = is smoker, 3 = likes sweets, 4 = likes eating, 5 = likes fishing.\n\n Type what number you want but only choose one: ")))

is_not_a_smoker = "Megan is your perfect match"
is_a_smoker = "Darel is your perfect match"
likes_sweets = "Martha is your perfect match"
likes_eating = "Quess is your perfect match"
likes_to_fish = "Daisy is your pperfect match"

print(block)

if block == 1:
    print(is_not_a_smoker)
elif block == 2:
    print(is_a_smoker)
elif block == 3:
    print(likes_sweets)
elif block == 4:
    print(likes_eating)
elif block == 5:
    print(likes_to_fish)
else:
    print("Were sorry, but their is no pefect match for you")
Steven Parker
Steven Parker
243,656 Points

Not quite, that "print" prevents the answer from being put into the variable "block".

Steven Parker
Steven Parker
243,656 Points

The "input" statement puts out your prompt by itself, so you don't need "print" with it. But it looks like you do want to convert the answer into a number, so perhaps you meant to put "int" instead of "print":

block = int(input(" 1 = is not a smoker, 2 = is smoker, 3 = likes eating, 4 = likes fishing, 5 = likes sweets.\n\n Type what number you want but only choose one: "))

thx