-1
a = raw_input 'type x here and see what happens'
    if a (INCLUDES) 'x'
        print 'y'

What's that INCLUDES command? Is there a better way around this?

I am a fan of the web comic Homestuck, in which trolls each have a different way of typing, called quirks. I'm working on a "quirk text" to English translator in Python (here's two characters with different quirks I.M.-ing) I want to make them type like normal humans.

David Cain
  • 16,484
  • 14
  • 65
  • 75

2 Answers2

5

Your code is not valid pythonic. In Python:

a = raw_input('type x here and see what happens')

if 'x' in a:
    print 'y'

The function raw_input() returns a string; the in syntax matches 'x' against your string (this is what your INCLUDE pseudo-code stands for). If 'x' is found, print 'y' is invoked, printing a 'y' on your console.

dcsordas
  • 232
  • 1
  • 3
  • 9
  • ah, I see, but if I type in "excalibur" then it prints y. How do I turn "excalibur" into "eycalibur" – Westley Twain Oct 18 '12 at 01:45
  • It prints 'y' because the 'x' matches in 'excalibur', which is expected. I do not understand the second part... if you'd like to match for 'y', just replace the 'x' in the `in` statement. If not, please clarify... – dcsordas Oct 18 '12 at 01:50
1

Try this:

a = raw_input()
if "pattern" in a:
    print "match"

All the magic is the keyword in

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223