very new to Python. I have a definition that I can get to print everything I want with print(), but am not able to find a way to return all that information.
For example, when counting the number of letters, the number and percentage of Es (lower and upper), I want to return the following to be printed by a test:
"The text contains ", alpha_count, " alphabetic characters, of which ", ecount," (", letter_percent(ecount, alpha_count),"%) are 'e'."
import math
def analyze_text(text):
ecount = text.count("E") + text.count("e")
alpha_count = 0
def letter_percent(ecount, alpha_count):
return 100 * float(ecount)/float(alpha_count)
for letter in text:
if letter.isalpha() ==True:
alpha_count += 1
An example of test:
from test import testEqual
text2 = "Blueberries are tasteee!"
answer2 = "The text contains 21 alphabetic characters, of which 7 (33.3333333333%) are 'e'."
testEqual(analyze_text(text2), answer2)