Isaac G
Isaac G

Reputation: 1

How to have something print only once?

I'm unsure why it's taking my answer, and instead of continuing onto the next question, it repeats it once more before doing so?

Also, after the second question (there's only two), it shows them both in parentheses still? Please help me, thank you. ^_^

Here's the code by the way:

print (raw_input('What is your date of birth?')) 
y = raw_input('What is your date of birth?')
print ('Your date of birth is ' + y)
print (raw_input('What is your last name? '))
x = raw_input('What is your last name?')
print ('Your last name is ' + x)
print ('Your date of birth is ' + y, 'Your last name is ' +x)

I'm also using python 2.5.4.

Upvotes: 0

Views: 1434

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121386

raw_input() itself already prints the prompt. You are then also printing the return value of the raw_input() call. You then repeat the raw_input() function call again.

Remove the print(raw_input(..)) lines; they are redundant:

y = raw_input('What is your date of birth?')
print 'Your date of birth is ' + y
x = raw_input('What is your last name?')
print 'Your last name is ' + x

Next, in Python 2, print is not a function, but a statement. You are treating it as one however, but Python sees the (.., ...) part (with a comma) as producing a tuple. Remove the parentheses:

print 'Your date of birth is ' + y, 'Your last name is ' + x

Now the whole line is part of the print statement as separate arguments for it, printing the two string results with a space in between.

Upvotes: 4

Related Questions