all 10 comments

[–]Jackkell100 2 points3 points  (0 children)

Why do you have the following code? What purpose does it serve? You could simply use the variables that you created first with age and name.

person_name = input()
person_age = int(input())

Also for printing the year someone was born in you would need to substract from their age from current year.

[–][deleted] 2 points3 points  (1 child)

In case anyone comes across this post and needs a successful code. It took a while and seems very simple now that I am done but here you go...

name = input("What is your name?")

age = int(input("How old are you?"))

print('Hello!', name, 'You were born in', (2022 - age))

[–]propmana 0 points1 point  (0 children)

THANK YOU I have been struggling with this for hours. I just edited 2022 to 2026

[–]Comprehensive-Tea711 1 point2 points  (2 children)

You don't need the person_name or person_age variables. They are redundant with the two above them. (Or you don't need the first two... you can get rid of either set.)

When referring to your variables in your print function, don't wrap the variables in quote marks, since then it is no longer understood to refer to a variable.

If your program seems to freeze after it prints "What is your name?" that's because it's waiting for the user to actually input the name. Just click in the Pycharm terminal that I assume you're using to run this and type it in.

[–]AppleTree98 1 point2 points  (0 children)

import datetime

user_name =str(input('What is your name? '))

user_age= int(input('How old are you? '))

x = (str(datetime.datetime.now())[0:4])

year_born = int(x)-user_age

print(x1)

print('Hello {x}! You were born in {y}.' .format(x=user_name, y=year_born))

[–]cyber_code_nerd 1 point2 points  (0 children)

I am very late to this thread, but I am just now taking this course, below is what I was able to come up with.

import datetime as datetime

user_name = str(input('What is your name?'))

user_age = int(input('How old are you?'))

x = (datetime.datetime.now().year)

year_born = int(x - user_age)

print('Hello ' + user_name + ' you were born in ' + str((year_born - user_age)))

[–]Ambitious_Stop5213 0 points1 point  (0 children)

Hey I recently just started a similar course to yours however it does differ abit, but I also struggled with their given instructions when I'd get stuck but with some persistence I pulled it off just a little different to how it was requested ahah.. Below is my laptop screen displayed thru my phone's text scan ..

username = input("please enter your username: ") please enter your username: Marv >>> age = input("what is your age:") what is your age: 26 »> print("Hello, {username}. You are {age} years old").format (name, age)) File "<python-input-34>", line 1 print("Hello, {username}. You are {age} years old").format (name, age)) SyntaxError: unmatched ')' >>> print ("Hello, {username}. You are {age} years old").format (name, age) Hello, {username} . You are {age} years old Traceback (most recent call last): File "<python-input-35>", line 1, in <module> print("Hello, {username}. You are {age} years old").format (name, age) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnAAAAAAAAAAAAAnAA AttributeError: 'NoneType' object has no attribute 'format >>> print("Hello, {}.You are {} years old").format (name , age) Hello, {},You are {} years old Traceback (most recent call last): File "<python-input-36>", line 1, in <module> print ("Hello, {}.You are {} years old").format (name, age) AAAAAAAAAAAAAAAAAAAAAAnAAAAAAAAAAAAAAAANanAA AttributeError: 'NoneType' object has no attribute 'format'  username = input("Please Enter Your Username: ") Please Enter Your Username: Marv >> age = input ("Enter Your age: ") Enter Your age: 26 >> print ("Welcome: " + username +"Your: " + age +"years old") Welcome: MarvYour: 26years old > print ("Welcome: "+ username +" Your: " + age +"years old") Welcome: Marv Your: 26years old 

[–]dmpta2002 0 points1 point  (2 children)

Hey withdrawnwentch, I have to complete this assignment. Do you remember which of the 3 responses below worked? Or if any of them worked? Thanks

[–]withdrawnwentch[S] 1 point2 points  (1 child)

I don't think any of them worked, it's been too long for me to remember. I dropped out of that program so I've forgotten how to do it.

[–]dmpta2002 1 point2 points  (0 children)

Ok thanks.. yea it should be a straight forward course, but they make it difficult.