2016-11-02 39 views
-3
print("what type of device do you have phone, tablet or laptop?") 
device = input ("phone/tablet/laptop:") 

電話に応答したら、なぜ電話の質問には行かないのですか?このコードはどのように動作させることができますか?

def phone(): 
    print("Do you have an iphone or samsung?") 
    phone = input ('iphone/samsung:') 

if phone == "iphone": 
    print("which type of iphone do you have?") 
    phone = input ("iphone:") 

if phone == "samsung": 
    print("which type of samsung do you have?") 
    phone = input ("samsung type:") 

電話に応答したら、なぜタブレットの質問には行かないのですか?

def tablet(): 
    print("What type of tablet do you have?") 
    tablet = input ("android tablet or ipad:") 

電話に応答したら、なぜノートパソコンの質問には行かないのですか?

def laptop(): 
    print("What type of laptop do you have?") 
    laptop = input ("windows/ios:") 
+2

適切な関数を呼び出してください。if device == "phone":phone() ' – vesche

答えて

1

入力内容が電話機、タブレット、ノートパソコンのいずれであるかを評価する必要があります。 if文にはこれらを使用できます。彼らが「電話」を入力した場合は、電話機能を呼び出します。

print("What type of device do you have? Phone, Tablet or a Laptop?") 
device = input("phone/tablet/laptop: ") 
if device == 'phone': 
    phone() 
elif device == 'tablet': 
    tablet() 
elif device == 'laptop': 
    laptop() 
関連する問題