I’m having trouble with an assignment a teacher made. I’m a python newbie so I don’t really understand the language.
I need to create a function that given a string of words and looks for the word with more “a” on it and if there are two words with the same number of “a” prints the first one.
Edit 1:
Yes well my idea was to look at each word and use something like str.count("a") and then print the word with the highest value
This answer should be pretty simple, even for beginners, because it uses only very basic commands:
Basically, it uses the .split() function of a string to split the string into separate words. Then the for loop goes through each word, noting how many ‘a”s there are in each word and if there are more than x words, it updates x with the number and puts the word in the ‘word’ variable.
When the loop gets another word with more ‘a”s, then it will updates x again and word again, but if it gets a word with less ‘a”s, then it will do nothing.