r/PythonLearning • u/Memo_Da_P1ug • Oct 06 '25
Help!
I’m taking a coding course to learn Python. However, I’ve been stuck on this question for about two days now. I’ve tried rewriting the code to where the name and last name are on the same line and it still says I have an extra row. How can I fix this issue and what did I do wrong? I want to make sure I fix my mistake and understand what I did wrong.
3
u/gra_Vi_ty Oct 06 '25 edited Oct 06 '25
In the question see,name has both first and last name ,but in your code you print first and last name in different print statement,which consumes extra row
6
u/NorskJesus Oct 06 '25
And he is not using the variables to print the result
4
u/gra_Vi_ty Oct 06 '25
Yeah I didn't saw that ,he at starting stage let him know what's his mistakes so he can correct it you explain it to him
1
1
u/gra_Vi_ty Oct 06 '25
Or you could could add end=' ' at first print statement,this end =' ' function makes the just output of below print statement stick to the above output print statement (end=' ' in between quotes space needed okay whatever you give inside quote will be between the output of two print statements)
52
3
u/_Alpha-Delta_ Oct 06 '25
The output of your program looks like this:
Steve
Sanders
91 Station Road
London EC05 6AWEither merge the two first prints in one, or use print("Steve", end=" ") on the first one
You should also probably use the variables instead of hard coding the result.
1
u/Memo_Da_P1ug Oct 06 '25
This was very helpful! Thank you
2
u/cgoldberg Oct 06 '25
You also have hardcoded strings in your print function.
You should do:
print(f"{name} {last_name}")1
u/DragonVect Oct 06 '25
Teach me Python, Master!
1
u/Marten1974 Oct 06 '25
Just in case you really do not know the notation: f" <some text> {something that is a string like a variable or return a string} <someother text here>" is the syntax
1
u/romainmoi Oct 06 '25
Or the older (but not outdated) way of
print(name, last_name)1
u/_Alpha-Delta_ Oct 06 '25
Or just create a variable named
fullName, and set it toname + " " + last_name2
u/romainmoi Oct 06 '25
Python naming convention for variables is using snake_case instead of camelCase. Other than that you’re right!
2
3
u/Free-Psychology-1446 Oct 06 '25
Well, you are printing 4 rows, so no surprise there.
Also don't assume, that the test will use the same input as they gave you in the example. Why did you hardcoded the answers from the example anyway?
1
u/KeyBump4050 Oct 06 '25
Have you ever seen Mail come in where the first and last names are on separate lines?
1
u/NeedleworkerIll8590 Oct 06 '25
You are printing the names seperately rather than together, how the test requires you to
1
u/hshsjdkfkd Oct 06 '25
Use the variables that you created bro. So for example instead of print(”Steve”) do print(name)
1
1
1
1
u/WysZe91 Oct 07 '25
The result displays 4 lines instead of 3. The first and last name must be collected. And use your variables.
1
u/JorgiEagle Oct 07 '25
Each print statement prints on a new line,
You have 4 print statements -> 4 lines
You want to do:
print(name, last_name)1
u/MyMashall Oct 07 '25
Input take a string (a list/array of words) from the standard input, generally your terminal aka shell, and store it in a variable. "print" on the other hand takes a string and display it on the standard output, once again generally you shell. So to use print you just pass the string (the variable) that you got from input() and give it to print.
1
u/hardyhrdhead Oct 08 '25
Instead of “print(“Steve”)” use “print(name)” which uses the variable that you created, and that will also allow you to enter different inputs and have those show up instead of “Steve” every time
1


26
u/FoolsSeldom Oct 06 '25
When you write code to ask for the user to enter something, because you don't know what they will enter, you give it a label (a variable). Then when you want to output what they entered, you refer to the variable.
For example,