2013-09-05 42 views
-2

python新手。似乎无法得到这个工作...语法错误无效,我该怎么办?

print = 'Press "U" and "Enter" for upper case.' 
print = 'Press "L" and "Enter" for lower case.' 
print = 'Press "C" and "Enter" for Capitalisation.' 

letter = input("Please type a letter and press enter: ") 
if letter == u: print '"THE MOST PROFOUND TECHNOLOGIES ARE THOSE THAT DISAPPEAR: THEY  WEAVE THEMSELVES INTO FABRIC OF EVERYDAY LIFE UNTIL ARE INDISTINGUISHABLE FROM IT" [MARK  WEISER, THE COMPUTER FOR THE 21ST CENTURY, SCIENTIFIC AMERICAN, SEPT. 1991]' 
if letter == l: print '"the most profound technologies are those that disappear: they  weave themselves into fabric of everyday life until are indistinguishable from it" [mark weiser, the computer for the 21st century, scientific american, sept. 1991]' 
if letter == c: print '"The most profound technologies are those that disappear: they weave themselves into fabric of everyday life until are indistinguishable from it" [Mark Weiser, The Computer for the 21st Century, Scientific American, Sept. 1991]' 

还我怎么能改善方案,使用户可以用另一个词替换一个词 。

+2

使用'print'在py3.x的功能和不使用它作为一个变量名。 –

+4

'print = ???'这是错误。 –

+0

[Python 3打印时的语法错误]的可能的重复(http://stackoverflow.com/questions/826948/syntax-error-on-print-with-python-3) –

回答

0

也许像

formats = {"U": {"text": "upper case", "func": str.upper}, 
      "L": {"text": "lower case", "func": str.lower}, 
      "C": {"text": "Capitalization", "func": lambda x: x} 
      } 

data = '"The most profound technologies are those that disappear: they weave themselves into fabric of everyday life until are indistinguishable from it" [Mark Weiser, The Computer for the 21st Century, Scientific American, Sept. 1991]' 

for c in formats: 
    print('Press "{}" and "Enter" for {}.'.format(c, formats[c]['text'])) 

letter = input("Please type a letter and press enter: ") 
if letter in formats: 
    print(formats[letter]['func'](data)) 
+0

这个工作适用于3.3.2> – FluffySnot

+0

@ user2750488它应该 – cmd

0

应该说

print('Press "U" and "Enter" for upper case.') 
print('Press "L" and "Enter" for lower case.') 
print('Press "C" and "Enter" for Capitalisation.') 

我推荐使用蟒蛇功能与string.replace替换字符串:)

http://docs.python.org/2/library/string.html

+0

这是我第二次犯这个错误......非常感谢。 – FluffySnot

+0

如果固定它,标记为选中;) –

+0

仍然有另一个错误,但您修复了无效的语法。 – FluffySnot

0
print('Press "U" and "Enter" for upper case.') 
0

还你或许应该使用功能上一样()在您的用户输入上,以计及大写和小写值:

if letter.upper() == U ........ 
+0

我怎么用这个? – FluffySnot

+0

后面几行:'letter = input(“请输入一个字母,然后按回车键:”)'它会将任何他们按下的值,并将其转换为大写,所以它会一致无论如何如果在提示时键入小写或大写。请注意,您当然应该检查字母的大写字母值。 – user2366842