0

Is there a way in Python where if a letter matchs any letter in a word it carries on the code so

X=str(input("input a word"))
Word="hello"
If x= Word() 
    a=a+1

So if Is there a way to say if I put x as "h" or "e" it will do the section of code

Sorry I know this is vague and I'm really bad at Python.any help will be amazing

2 Answers2

0

Use in:

if x in Word:
    a = a + 1
zondo
  • 19,901
  • 8
  • 44
  • 83
0

This is answered in this post

The method is called "in"

In your example:

the_string = raw_input('Enter text here')
if 'hello' in the_string:
    a = a + 1
Community
  • 1
  • 1
Neil P
  • 401
  • 3
  • 6