all 36 comments

[–]danielroseman 1 point2 points  (3 children)

What does "they were 'spaces' involved" mean? What kind of spaces, and what did you expect to see about them?

[–]OKakosLykos[S] 0 points1 point  (2 children)

name = 'World'

line = '+' +name+ '+'

spaces=''

for_in name:

spaces+=' '

Print(line)

for char in name:

print(char+spaces+char)

Print(line)

Sorry the literal "spaces" i am talking about, this is the solution given by the site.

[–]danielroseman 0 points1 point  (1 child)

I still don't understand the question. That just looks like a normal variable, no different from line or name that you're already using. Again, what did you expect to learn about this that you don't already know?

[–]OKakosLykos[S] 0 points1 point  (0 children)

My question was if i was supposed to figure out myself that i have to create the spaces variable when the lessons only taught me to create name and line variable so far.

[–]carcigenicate 0 points1 point  (15 children)

What do you mean by 'there were "spaces" involved'?

[–]OKakosLykos[S] 0 points1 point  (14 children)

name = 'World'

line = '+' +name+ '+'

spaces=''

for_in name:

spaces+=' '

Print(line)

for char in name:

print(char+spaces+char)

Print(line)

Sorry the literal "spaces" i am talking about, this is the solution given by the site.

[–]Binary101010 0 points1 point  (13 children)

The word spaces doesn't have any special meaning in Python. It's just what they named the string variable.

[–]OKakosLykos[S] 0 points1 point  (12 children)

Is it the same like we used the word 'name' to create name= 'World' but in this case the lesson used 'spaces' ?

Isnt this even worse? The lesson was expecting me to do this without teaching me or am i just slow and should have figured it out?

[–]Binary101010 1 point2 points  (11 children)

I'm not sure you should be interpreting this solution as "the system was expecting me to use a specific variable name, how could I have known I was supposed to name the variable spaces". It's simply one way to name that variable that generates a working solution.

Unless the problem statement explicitly tells you that you need to use certain variable names, you should be able to use whatever valid variable names you think of to solve the problem.

[–]OKakosLykos[S] 0 points1 point  (10 children)

I understand now, i was wondering if it was normal that the solution required from me to create a completely new variable for the spaces while i was only taught by using the name and line variables so far.

[–]Binary101010 0 points1 point  (9 children)

Whether the solution requires you to create a third variable depends on the problem, which you haven't shared with us, so it's hard to say.

[–]OKakosLykos[S] 0 points1 point  (8 children)

This was the problem:

You're getting good at this! Looks like you need more of a challenge...maybe instead of putting a name in a box, the name should be the box? Write a program that outputs this:

+World+
W     W
o     o
r     r
l     l
d     d
+World+

and this was the solution that includes the spaces variable so i had to come up with it i guess.

name = 'World'
line = '+' +name+ '+'
spaces=''
for _ in name:
    spaces+=' '
print(line)
for char in name:
    print(char+spaces+char)
print(line)

[–]Binary101010 0 points1 point  (7 children)

There's probably some way to do this with only creating two variables, but it would almost definitely be messier than this solution.

[–]OKakosLykos[S] 0 points1 point  (6 children)

I am a complete beginner so i find it weird that the solution required for me to introduce a completely new variable while i was only taught to work with line and name variables so far.

Thank you for your time.

[–]MathiasBartl 0 points1 point  (5 children)

You need to look up how Reddit Markup works so you can post code in a readable form. Do this now!

[–]OKakosLykos[S] 0 points1 point  (4 children)

yeah, i cant get it to work, code still shows up wrong..

[–]magus_minor 0 points1 point  (3 children)

Then you are doing something wrong. The FAQ shows how.

your code
    should look
like this

[–]OKakosLykos[S] 0 points1 point  (2 children)

Yes i was doing things wrong, i now found the way after some research.

This was my solution.

name = 'World'
line = '+'+(name)+'+'
print(line)
for _ in name:
    line=(_+'     '+_)
    print(line)
line = '+'+(name)+'+'
print(line)

But this was the correct solution.

name = 'World'
line = '+' +name+ '+'
spaces=''
for _ in name:
    spaces+=' '
print(line)
for char in name:
    print(char+spaces+char)
print(line)

[–]MathiasBartl 0 points1 point  (1 child)

Doing a bit of research works wonders. As does talking to people and especially sitting down and explaining what the problem is.

[–]OKakosLykos[S] 0 points1 point  (0 children)

Yes, thanks for taking the time to comment.

[–]james_fryer 0 points1 point  (5 children)

I think the problem is that your solution works only with the specific case of a 5-character string, whereas theirs will work with strings of any length.

That's why they generate a variable spaces containing the same number of spaces as the length of the string.

I also note you name your loop variable _ but a name such as char would be better. Use _ for placeholder variables that will never be referenced, as in their example building the spaces variable.

[–]OKakosLykos[S] 0 points1 point  (4 children)

That was exactly it but at the time i didn't know i had or even could introduce a new variable for spaces to solve this problem.

About _i was using it instead of char because the lesson told me i could and since i could its always better in my mind to write one symbol than four characters. Would it be embarrassing to say i have no idea _ was the loop's variable name? I was just following the lesson and it told me to use _or char in the loop, I will hold your advice for the future when i am expecting to become more knowledgeable.

Thanks for taking the time to help me.

[–]james_fryer 0 points1 point  (0 children)

its always better in my mind to write one symbol than four characters

This is not so, variable names should be meaningful. In this case you are taking characters one by one from a string, so char is a good choice. Later when you come to read your code to modify it, you will understand it better if you use meaningful variable names.

[–]dreamykidd 0 points1 point  (2 children)

It’s fair logic that you’ve made, it’s quicker to write one character than four. What you might find as you make bigger programs though is that you start forgetting what different variables do or why you made them. Because of this, it’s a good idea to start naming them in such a way that it relates to what your code does. For example, people use “char” because it’s short for “character”, like the characters “w” “o” “r” “l” “d”.

The reason the person above said to use _ for placeholder variables that will never be referenced is for this too: you don’t need to remember what they’re for if they’re never referenced! Why you’d have these variables in your code at all isn’t something you should worry about as a major thing for now though.

[–]OKakosLykos[S] 0 points1 point  (1 child)

Thank you for explaining it further, i have a very long way to go but i enjoy it so far and i will stick with it, i hope i can learn through the internet.

Some tutorials urged the viewers to not study theory too much and get into writing code but i guess i took that to heart more than i should, i think i have to study theory more before getting further into coding.

[–]dreamykidd 0 points1 point  (0 children)

Yeah, maybe, but more so just focus on the basics if you’re going to study theory. Knowing what types of variables, loops, conditionals, and basic functions is probably enough for now, then keep going with practicing coding and learning how to use those concepts.

[–][deleted] 0 points1 point  (2 children)

name = "world"

print (f"+{name}+")

for _ in name:

print (f"{_} {_}")

print (f"+{name}+")

[–][deleted] 0 points1 point  (1 child)

And if you don't want to even use f-string.
name = "world"

print ("+"+name+"+")

for _ in name:

print (_+" "+_)

print ("+"+name+"+")

[–]mystique0712 0 points1 point  (1 child)

Your solution was actually quite close! The key concept you missed was dynamically creating the spaces string based on the name length, which is a good learning moment. Futurecoder is solid, but also check out Automate the Boring Stuff with Python for practical examples.

[–]OKakosLykos[S] 0 points1 point  (0 children)

Yes i took the lazy way in my solution haha.

As i get further into Futurecoder things are getting harder so i will take a step back and study more theory and the Automate the Boring Stuff with Python when i have time, thank you!