return - Python returning a true statement even if false (trying to find if a letter exists in a program) -


i new coding, , quick answer of you. it's school assignment. here code:

def letter(r):      """determines if string contains uppercase or lowercase r"""      if 'r' in '**r**':         return "there letter r somewhere in there!"      else:         return "the letter r not located here!"  r = str(input('enter phrase: '))  print(letter(r)) 

the program run successfully, returns "if" string regardless of if letter r in phrase.

example console:

(executing file "has_r.py")

enter phrase: not

there letter r somewhere in there!

change if statement to:

if 'r' in r: .... 

the if statement runs r in "**r**"


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -