2017-01-25 5 views
-1

私はPythonでランダムネームジェネレータの基本コードを書こうとしています。これはまもなく使いやすいGUIを備えた完全に機能するWebアプリケーションになりますが、何らかの理由でプログラムが動作しません。ユーザ入力に関係なく、同じ条件分岐が実行され続ける

私はプログラムを実行するとき、ユーザーに "console"か "game"のどちらかを指定するように要求します。 「ゲーム」と入力すると、の代わりにルートの場合はのルートになります。

import string 
#This is a Name Generato 
print("Welcome To the first version of my name generator at the moment there is only 20 names but in the final version there will be 200 names with over 25 different tags") 
print("First of all what do you need a Console or a game Name?") 
console = input() 

if (console): 
    print("is it a,PS4,PS3,XBOX 360,XBOX ONE or PC") 
    print("NOTE:Wii,PSP and DS are not supported") 
    consolename = input() 
    print("The,",consolename) 
    print("Is good") 
    print ("now give me one or two key words that you would like in your name out of...") 
    print("happy,sad,depressed,fox,cow,cat,dog,wolf,lion,lil,lazy,forgetful,gaming,xxx,orthodox,apex,toXic") 
    firstname1=input() 
    secondname=input() 
    print(firstname1) 
    print(secondname) 
    print("Good Choice") 
else: 
    print("What game is it?") 
    print("Minecraft,Black ops 1//2/3,COD,Halo1/2/3/4/5/CE/Reach,Terraria,World of warcraft,League Of Legends") 
    print("NOTE:Type the Game As you see it!") 
    game1 = input() 
    print("Ah good choice eh") 
+1

コンソールは文字列です。それはいつも「真実」です。文字列と比較する!! –

+0

'console'文字列は、空の場合にのみ' False'になります。そのためには、 'input()'でを打つだけです。 – cdarke

答えて

1

文字列が入力されていて、Trueであるかどうかを確認しています。そのTrueは、空でない場合は常にtrueです。コンソール変数を文字列と比較する必要があります。これのようなものが仕事をします。

import string 
#This is a Name Generato 
print("Welcome To the first version of my name generator at the moment there is only 20 names but in the final version there will be 200 names with over 25 different tags") 
print("First of all what do you need a Console or a game Name?") 
console = input() 

if (console=="console" or console=="Console"): 
    print("is it a,PS4,PS3,XBOX 360,XBOX ONE or PC") 
    print("NOTE:Wii,PSP and DS are not supported") 
    consolename = input() 
    print("The,",consolename) 
    print("Is good") 
    print ("now give me one or two key words that you would like in your name out of...") 
    print("happy,sad,depressed,fox,cow,cat,dog,wolf,lion,lil,lazy,forgetful,gaming,xxx,orthodox,apex,toXic") 
    firstname1=input() 
    secondname=input() 
    print(firstname1) 
    print(secondname) 
    print("Good Choice") 
else: 
    print("What game is it?") 
    print("Minecraft,Black ops 1//2/3,COD,Halo1/2/3/4/5/CE/Reach,Terraria,World of warcraft,League Of Legends") 
    print("NOTE:Type the Game As you see it!") 
    game1 = input() 
    print("Ah good choice eh") 
+0

OPが変数名を 'console'以外のものに変更するのも良い考えです。 – Tagc

+0

うん、このコードは多くの変更が必要です。しかし、現時点では、OPが "IF"ステートメントを理解するのが良い。 –

関連する問題