这是一个python程序,我给它一个输入字符串dev它应该重新启动字符串php,反之亦然。但这不能正常工作。
#!/usr/bin/python
str = raw_input("enter the string to be printed:")
print(str)
if str == php :
print("dev")
else :
print("php")
答案 0 :(得分:0)
让我告诉你正确的方法:
示例simple.py
脚本:
s = raw_input("enter the string to be printed:")
words = ('dev','php')
print 'entered: ', s
if s in words:
print 'got: ', words[~words.index(s)]
现在,用法:
a)输入dev
字符串时:
python simple.py
enter the string to be printed:dev
entered: dev
got: php
b)输入php
字符串时:
python simple.py
enter the string to be printed:php
entered: php
got: dev
享受!