2016-07-31 9 views
-3

辞書/翻訳者を作成していますが、ユーザーに「hello」と「Hello」と書いてもらい、「Ronne」という結果を受け取ります。検索時に2つの結果を許可する方法

print ("English to Exrian Dictionary") 
search = input("Enter the word you would like to translate: ") 

if search == "Hello": 
    print ("Ronne") 
elif search == "Bye": 
    print ("Zio") 
else: 
    print ("No matches were found for '" + search + "'") 
+0

完全性を期すために、 '.lower()'アプローチに加えて、 '' Hello '、' hello ''で検索すれば ' - この場合はあまり明確ではないようですアプローチは '.lower()'を使うよりも、まだb知っている。 – jedwards

+0

'if ... elif ...'を使うのは2,3ワードで大丈夫ですが、より多くの単語を扱うには[dictionary](https://docs.python.org/3 /tutorial/datastructures.html#dictionaries)。 –

答えて

1

ちょうどこのように、あなただけ小文字にご入力を変換し、そして「こんにちは」との比較ができ

search = search.lower() 
if search == "hello": 
    print ("Ronne") 
+0

私はそれが同じ答えを得るために "Hello"または "こんにちは"を書くことをユーザーに許可したいと思う。 –

+0

@MichaelThinこれはまさにこれが行うことです。やってみなよ。 –

+0

しかし、私はユーザーの入力をしたい。このような。 search = input( "example:")。lower() –

0

を小文字に検索を変換し、ケースを無視する:

search = input("Enter the word you would like to translate: ").lower() 

if search == "hello": 
    print("Ronne") 
関連する問題