• anonymous
In Matlab: Write a program that accepts an input string and a character from the user and determines how many times the character appears within the string.
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  • jamiebookeater
I got my questions answered at in under 10 minutes. Go to now for free help!
  • anonymous
this is Python. Believe Matlab is C+
  • anonymous
there is a function defined to do that in python for lists. list.count(x) Return the number of times x appears in the list.
  • carlsmith
Matlab? In Python you can do def character_tally(): tally = 0 user_string = raw_input('Enter a string: ') user_character = raw_input('Enter a character: ') for each in user_string: if each == user_character: tally += 1 return tally If you're using Python3, remember to use input() instead of raw_input().

Looking for something else?

Not the answer you are looking for? Search for more explanations.