-2

パイソン初心者。これを機能させることはできないようです...

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

また、ユーザーが 1 つの単語を別の単語に置き換えることができるようにプログラムを改善するにはどうすればよいでしょうか。

4

4 に答える 4

0

言うべき

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

文字列を置き換えるには、pythons string.replace 関数を使用することをお勧めします:)

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

また、大文字と小文字の両方の値を考慮するために、おそらくユーザー入力で upper() のような関数を使用する必要があります。

if letter.upper() == U ........
于 2013-09-05T15:07:53.267 に答える