-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.

FluffySnot
  • 11
  • 4

4 Answers4

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

Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
0
print('Press "U" and "Enter" for upper case.')
Paddyd
  • 1,870
  • 16
  • 26
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 ........
user2366842
  • 1,231
  • 14
  • 23
  • how where would i use this? – FluffySnot Sep 05 '13 at 15:24
  • on the next couple lines after this: `letter = input("Please type a letter and press enter: ")` It will take the value of whatever they press, and convert it to upper case, so it will be consistent no matter if they type in lower case or upper case at the prompt. Note that you should then of course, be checking against upper case values for the letters. – user2366842 Sep 05 '13 at 16:03
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))
cmd
  • 5,754
  • 16
  • 30