Reputation: 9
How do I fix this error? The user test function needs to hold the inputs for a string and a character, these inputs then need to be called in the reverse and character count functions.
def user_test():
'''
:return: hold user input
'''
global user_string
global user_character
user_string = print(input("What is the string you would like to use:"))
user_character = print(input("What is the character you would like to use:"))
character_count(user_string, user_character)
reverse(user_string)
return user_string, user_character;
def reverse(user_string):
'''
:param: string
:return: reverses a string
'''
string = user_string
print (list(reversed(string)))
return string
def character_count(user_string, user_character):
'''
:return: counts the number of occurances of a character in a string
'''
string = user_string
toCount = user_character
counter = 0
for letter in string:
if( letter == toCount):
counter += 1
print(counter)
def main():
user_test()
main()
Traceback
Traceback (most recent call last):
File "C:\Users\Cheryl\Documents\Python Stuff\lab6_design.py", line 111, in <module>
main()
File "C:\Users\Cheryl\Documents\Python Stuff\lab6_design.py", line 108, in main
user_test()
File "C:\Users\Cheryl\Documents\Python Stuff\lab6_design.py", line 9, in user_test
character_count(user_string, user_character)
File "C:\Users\Cheryl\Documents\Python Stuff\lab6_design.py", line 34, in character_count
for letter in string:
TypeError: 'NoneType' object is not iterable
Upvotes: 1
Views: 614
Reputation: 31
print() returns None so user_string and user_character are None.
user_string = print(input("What is the string you would like to use:"))
user_character = print(input("What is the character you would like to use:"))
Change it to the following if you still want to print the input
user_string = input("What is the string you would like to use:")
print(user_string)
user_character = input("What is the character you would like to use:")
print(user_character)
Upvotes: 1