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

What's wrong with this code?

I have a few problems here. The first one is for some reason the information variable is, and so is the first comment. The second problem is why isn't my if statement exiting. I've tried to use break within a while loop. If it's Steven that replies, do you think this formatting is good enough or anyone else who might be helping me out.

information = input("Do you wanna fill out this information? Y/N: ")

full_name2 = input("What is your full name? ")
age = input("How old are you? ")
gender = input("What is your gender? ")
phone_number = input("What is your phone number? ")

questions = full_name2 + age + gender + phone_number

if information.lower() == 'n':
  sys.exit("Alright, bye.")
elif information.lower() == 'y':
    print("Alright then! Just fill out the questions below.")
    print(questions)


'''
Make something with y/n to check if they wanna be part of my family
If no they you want to "break"
If yes they need to go through a lot of stuff that they have to fill out
E.g. phone number, address, how old they're and so on.
Maybe do something so that they cannot write numbers in their names and the opposite with phone numbers
'''

1 Answer

Hi Mikkel,

I have rearranged your code to perform what I believe you want to do. Also, you must import sys in order to have access to the exit method. There is a much better way to format the output that the user enters besides simply concatenating it into one long string, but I'll leave that as an exercise.

import sys

information = input("Do you wanna fill out this information? Y/N: ")

if information.lower() == 'n':
    print("Alright, bye")
    sys.exit
elif information.lower() == 'y':
    print("Alright then! Just fill out the questions below.")
    full_name2 = input("What is your full name? ")
    age = input("How old are you? ")
    gender = input("What is your gender? ")
    phone_number = input("What is your phone number? ")
    print(full_name2 + age + gender + phone_number)

Hope this helps!