1

I want my program to print the value of the variable 'sob' when I write: write("sob")

Code:

str = input(">")
sob = input(".")
if str == ('write("' + sob + '")'):
    print(sob)
else:
    print("SYNTAX ERROR")
MLCLOUD
  • 11
  • 7

2 Answers2

0

Instead of using input() use raw_intput():

str = raw_input('>')
sob = raw_input(".")

if str == ('write("' + sob + '")'):
        print(sob)
else:
        print("SYNTAX ERROR")

input() interprets the input you enter as python commands, whereas raw_input() returns a string.

user3814613
  • 210
  • 1
  • 2
  • 9
0

Try this

CODE

sob = raw_input('Type write("sob"): ')
sob = sob.lower()
if sob == 'write("sob")':
    print(sob.lstrip('Type write("').rstrip('")'))
else:
    print("Error")

RESULT

sob
PyNoob
  • 907
  • 3
  • 15
  • 29