(PYTHON 3) having trouble with this question. Prompt the user to enter a string
ID: 3780162 • Letter: #
Question
(PYTHON 3) having trouble with this question.
Prompt the user to enter a string of their choosing. Output the string. Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this function. Extend the program by calling the get_num_of_characters() function and then output the returned result. Extend the program further by implementing the output_without_whitespace() function. output_without_whitespace() outputs the string's characters except for whitespace (spaces, tabs).Explanation / Answer
def get_num_of_characters(inputStr):
sm =0
for ch in inputStr:
sm+=1
return sm
def output_without_whitespace(inputStr):
s = ""
for ch in inputStr:
if ch!=' ':
s = s+ch
return s
if __name__=='__main__':
s= raw_input("Enter a sentence or phrase: ")
print("You entered: "+s)
print("Number of characters: "+str(get_num_of_characters(s)))
print("String with no whitespace: "+output_without_whitespace(s))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.