Closed. This question is
CodePudding user response:
In script mode, your is_valid_input
function is undefined when main()
will be run. Place this block at the very end of your code (after the definition of is_valid_input
):
if __name__ == "__main__":
main()
Regarding your code per se, I am not sure what you want to do exactly, but below is a way to make the is_valid_input
function only test an existing string:
def main():
letter_guessed = ''
while not is_valid_input(letter_guessed):
letter_guessed = input("please guess a letter: ").lower()
def is_valid_input(letter):
"""
this function will check if the the guess is ok
:param letter_guesses: the user's guess
:type letter_guesses: str
:return: True if the guess is complies with the rules and False if not
:rtype: bool
"""
import string
if letter.isalpha() and len(letter) == 1:
return True
else:
return False
if __name__ == "__main__":
main()
CodePudding user response:
The answer provided by @mozway is perfect. If you are looking to see the returned value in the terminal then catch the returned boolean value from the function is_valid_input
and print it.