0

We have an assignment to create a code where there is user input and it should print out like this.

What is your name? Amanda
How old are you? 2005

Hello Amanda! You were born in 2005.

My Code:

user_name = input('What is your name?')
user_age = int(input('How old are you?'))
birth_year = (2021 - user_age)
print()
print('Hello', user_name, '!', 'You were born in', birth_year, '.')

My Output:
What is your name?'nikki'
How old are you?'27'
()
('Hello', 'nikki', '!', 'You were born in', 1994, '.')

Process finished with exit code 0

I can't figure out how to get the parentheses to not go around the output print string. I am doing everything we were taught so super confused. I also have to enter the input in '' or else it won't work.I've tried separating the string into two separate print strings. That didn't work. Also tried changing the commas to + which was even more of an error.

not_speshal
  • 22,093
  • 2
  • 15
  • 30
nycmcc
  • 15
  • 5

1 Answers1

0

Looks like you are using Python 2.x by accident instead of Python 3.x.

In Python 2, print is a keyword instead of function, so print () prints an empty tuple.

Also in Python 2 input() evaluates user's input as a Python expression. To read a string, you had to use raw_input(). In Python 3 input() does what raw_input() did.

lqc
  • 7,434
  • 1
  • 25
  • 25