Greetings everybody,
First off, I'm a 71 year old retired male at home trying to learn python. No schools involved. I just thought this was the best forum to start. I'm using a college testbook to study with.
I'm stuck with this question: "Write a loop that counts the number of space characters in a string.
Recall that the space character is represented as ' '."
with strings. How do you get a count in here??? I'm probably missing the point on something.
I did google and found this: print(y.count(' ')) Works well,but I still am missing the point on running this through a loop. How do I get a count in here?
First off, I'm a 71 year old retired male at home trying to learn python. No schools involved. I just thought this was the best forum to start. I'm using a college testbook to study with.
I'm stuck with this question: "Write a loop that counts the number of space characters in a string.
Recall that the space character is represented as ' '."
y = ' ' for y in "To be, or not to be? That is the question." \ " Whether ’tis nobler in the mind to suffer" \ "the slings and arrows of outrageous fortune," \ " or to take arms against a sea of troubles, " \ "and, by opposing, end them?" : if y ==' ' y = y + 1 print(y)The only thing i get when running is either the string or an error saying something about mixing int's
with strings. How do you get a count in here??? I'm probably missing the point on something.
I did google and found this: print(y.count(' ')) Works well,but I still am missing the point on running this through a loop. How do I get a count in here?