2016-11-10 8 views
-4
print("what type of device do you have phone, tablet or laptop(put brackets at  the end of your answer)?") 

answer = input ("press enter and type in your answer. phone(), tablet() or   console()") 

def phone(): 
    import webbrowser 
    print("Do you have an iphone or samsung?") 
    answer = input ('iphone/samsung:') 
    if answer == "iphone": 
    print("what type of iphone?") 
    answer = input ('5, 6 or 7:') 
    if answer == "samsung": 
    print("what type of samsung do you have?") 

    answer = input ('s5, s6 or s7:') 
+3

あなたのインデントを修正して、投稿の*本文*に質問してください。 –

+1

Pythonでは、字下げが重要です。あなたのコードは正しくインデントされていません。単純にstackoverflowに貼り付け、それを選択して 'Ctrl' +' K'でコードとしてマークしてください – phihag

+0

また、* debugging *を探している質問(なぜこのコードは動作しませんか)は[mcve]と尋ねる必要があります。電話()、電話()、またはコンソール()の入力を押して答えを入力する理由は何ですか? –

答えて

1

インデントブロックは、より注意してください!

def phone(): 
    import webbrowser 
    print("Do you have an iphone or samsung?") 
    answer = input ('iphone/samsung:') 
    if answer == "iphone": 
     print("what type of iphone?") 
     answer = input ('5, 6 or 7:') 
    if answer == "samsung": 
     print("what type of samsung do you have?") 
     answer = input ('s5, s6 or s7:') 
x = input("press enter and type in your answer. phone(), tablet() or console() ") 
if x == 'phone()': 
    phone() 
elif x == 'tablet()': 
    tablet() 
elif x == 'console()': 
    console() 
+0

@ cricket_007 Ops、ありがとう:) –

+0

これはまだ質問に答えるものではありません。なぜ入力しないと答えを入力して答えを入力しないのですか?phone()、tablet()、console() ) "'仕事? –

+0

編集された、これは彼が探しているものですか? –

1

基本的に、何を持っていることはこれです...

def foo(): 
    print("stuff") 

answer = input("type foo()") 

そしてanswer == "foo()"Trueです。

foo()は決して呼び出されませんでしたが、文字列として入力しただけです。

実行する必要があります。

exec(answer) 

しかしexec本当に悪いので、代わりに、あなたが代わりに対応する機能を呼び出すためにifelif年代を使用する必要があります。

if answer == 'foo()': 
    foo() 
関連する問題