0

I created a program that asks a bunch of input questions and prints out the following line, for example, Marc Gibbons is a 103 year old male. He was born in Ottawa and his SIN # is 1234567890.

But when I keep getting an error.

enter image description here

from datetime import datetime

def main():
name = input('Please enter your name:')

sex = input('Please enter your sex, Male (M) or Female (F) or Non-Binanry(N):')

birthday = input ('Enter your date of birth in YYYY-mm-dd format:')

birthday1 = datetime.strptime(birthday, '%Y-%m-%d')
age =  ((datetime.today() - birthday1).days/365)

place = input('What City were you born in:')

    try:
        sin = int(input('What is your sin number:'))
    except ValueError:
        print('Error:Please enter a number')

print(f'{name} is a {age} years old {sex}. He was born in {place} and her SIN # is {sin}')

# Do not edit below
if __name__ == '__main__': main()
3
  • Maybe you want the print statement indented in the main() function? Commented Nov 27, 2019 at 23:20
  • 1
    move print(f"...") after sin = ... Commented Nov 27, 2019 at 23:21
  • That worked. Thank you! Commented Nov 27, 2019 at 23:26

2 Answers 2

2

just make sure that print(f'{name} is a {age} years old {sex}. He was born in {place} and her SIN # is {sin}') indented right inside the function

Sign up to request clarification or add additional context in comments.

2 Comments

How do I incorporate he/she in my sentence based on the answer provided by the input, female or male?
you can add pronoun = 'he' if sex=='m' else 'she' and edit print(f'{name} is a {age} years old {sex}. {pronoun} was born in {place} and her SIN # is {sin}')
1

move the print state into the function. The current indentation means main() (containing your name var) is not in the same scope as the print function:

from datetime import datetime

def main():
    name = input('Please enter your name:')

    sex = input('Please enter your sex, Male (M) or Female (F) or Non-Binanry(N):')

    birthday = input ('Enter your date of birth in YYYY-mm-dd format:')

    birthday1 = datetime.strptime(birthday, '%Y-%m-%d')
    age =  ((datetime.today() - birthday1).days/365)

    place = input('What City were you born in:')

    try:
        sin = int(input('What is your sin number:'))
    except ValueError:
        print('Error:Please enter a number')

    # Indent here to inside the function
    print(f'{name} is a {age} years old {sex}. He was born in {place} and her SIN # is {sin}')

Hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.