Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (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.

OpenStudy (anonymous):

this is Python. Believe Matlab is C+

OpenStudy (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.

OpenStudy (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().

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!