Explanation:
Number of characters: 46
String with no whitespace: Theonlythingwehavetofearisfearitself.
########################################################
def get_num_of_characters(inputStr):
count = 0
for i in range(0,len(inputStr)):
count = count + 1
#count = len(inputStr)
return count
def output_without_whitespace(inputStr):
#statement = statement.strip()
statement2 = ' '
for i in range(0,len(inputStr)):
if(inputStr[i] == ' '):
statement2 = statement2
else:
statement2 = statement2 + inputStr[i]
inputStr = inputStr.replace(" ", "")
return statement2
inputStr = input('Enter a sentence or phrase: ')
print()
print('You entered:', inputStr)
num = get_num_of_characters(inputStr)
print()
print('Number of characters:', num)
print('String with no whitespace:',output_without_whitespace(inputStr))
#if __name__ == '__main__':
# Think I'm supposed to use this if statement
########################################################
'''ERROR MESSAGE WHEN RUNNING TEST
Unit test
0/1
Tests that get_num_of_characters() returns 46 for "The only thing we have to fear is fear itself."
Your output
Enter a sentence or phrase: Traceback (most recent call last):
File "zyLabsUnitTestRunner.py", line 4, in <module>
from zyLabsUnitTest import test_passed
File "/home/runner/local/unit_test_student_code/zyLabsUnitTest.py", line 1, in <module>
from main import get_num_of_characters
File "/home/runner/local/unit_test_student_code/main.py", line 19, in <module>
inputStr = input('Enter a sentence or phrase: ')
EOFError: EOF when reading a line'''