0

I am doing some tests in order to get onto a coding bootcamp. I am very new to coding and I have been stuck on this question for 2 days now and any help would be appreciated.

This is the question: Create a program that determines the number of occurrences of each letter in the quote "You can have data without information, but you cannot have information without data.", and output a list with each letter and its frequency.

This is the given pseudocode:

Create a variable to store the given string "You can have data without information, but you cannot have information without data." Convert the given string to lowercase Create a list containing every lowercase letter of the English alphabet

for every letter in the alphabet list: Create a variable to store the frequency of each letter in the string and assign it an initial value of zero for every letter in the given string: if the letter in the string is the same as the letter in the alphabet list increase the value of the frequency variable by one. if the value of the frequency variable does not equal zero: print the letter in the alphabet list followed by a colon and the value of the frequency variable

This is the code I have written so far, am I close to getting there going of the instructions above?

text = "You can have data without information, but you cannot have information without data."
text = text.lower
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for letter in alphabet:
 alphabet = 0
 if letter in alphabet == text:
  text +=1
 if text != 0:
  print(letter(text))

I am getting this syntax error when I run my code:

line 6, in <module>
    if letter in alphabet == text:
TypeError: argument of type 'int' is not iterable

I was expecting the output to be this:

a : 10 b : 1 c : 2 d : 2 e : 2 f : 2 h : 4 i : 6 m : 2 n : 7 o : 9 r : 2 t : 10 u : 5 v : 2 w : 2 y : 2

  • 1
    Does this answer your question? [Count the number of occurrences of a character in a string](https://stackoverflow.com/questions/1155617/count-the-number-of-occurrences-of-a-character-in-a-string) – Mushroomator Nov 09 '22 at 18:48

0 Answers0