Ch.3 Ex.16 working on console but exercise not achieved


#1

Exercise 5.1: And Now, For Something Completely Familiar

Here's my trouble, my code seems to actually works, but i can't complete the exercise since the site asks me "have you displayed len(ma_string)?"

I tried with 2 distinct configurations that i posted below

Anyone understand anything ?

ma_string = "done"
print len("ma_string"); print ma_string.upper()

&

ma_string = "done"
print len("ma_string")
print ma_string.upper()


#2

"done" is 4 characters
"ma_string" is 9 characters

which is being asked for?


#3

sorry, looks like the console blocked on my precedent code, which contained 9 chararacters, let's say the question is about done


#4

ma_string is a variable that refers to "done"

ma_string refers to a 4-character string
"ma_string" is a 9-character string

The instructions ask you to print the length of ma_string

Which one do they mean?
Worst case you can just try all options, there are two.


#5

did this : ma_string = "ma_string" and it worked !
not sure i totally understood why, but thanks any way !


#6

I don't think that's what you were meant to do.

You would use a variable to refer to some data.

For example, you could have a variable called my_name:

my_name = "bob"

so If I need to access my name, I can use that variable. However, this would be quite useless:

my_name = "my_name"

I doubt that my name really would be my_name, what I'd want to know is the length of my name, that's 3 for bob.


#7

yes, that's why i told that i didn't understood why it suddenly worked,

in the instructions they told me that i could put any string to the variable,

then to display the length of ma_string,

but ma_string = done didn't worked,

and the error seems to come from the number of characters,

for example ma_string = "012345678" works, but ma_string = "01234567" doesn't


#8

Had you defined done before doing that? Otherwise that would be undefined. You might instead want to use the value "done" which is data, not a name referring to some value in the program

Also, the word "works" is terrible at describing what's going on, avoid it for just about all purposes. Same with "wrong"


#9

got it, i should have typed print len(ma_string) instead of print len("ma_string")


#10

sorry i mean't ma_string = "done"
thanks for the advice


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.