-2

New to python. Can't seem to get this to work...

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]'

also how can I improve the program so that the user can replace a one word with another word.

4

4 回答 4

0

Should say

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

I'd recommend using pythons string.replace function for replacing strings :)

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

于 2013-09-05T15:04:11.727 回答
0
print('Press "U" and "Enter" for upper case.')
于 2013-09-05T15:05:35.360 回答
0

also you should probably be using a function like upper() on your user input to account for both lower and upper case values:

if letter.upper() == U ........
于 2013-09-05T15:07:53.267 回答
0

Maybe something like

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))
于 2013-09-05T15:47:16.703 回答