2017-12-08 3 views
0

子供がいたずらリストに載っていれば、選択肢5を提示したいが、素敵なリストには選択肢6を提示することが望ましい。私の問題は、リストへの割り当てはタプル値のランダムな選択です。ランダムな選択肢に条件を付けるにはどうすればよいですか?

import random, time # allowing use of random and delays 
choice=[ 
'eddie', 
'dan', 
'erin', 
'josh', 
] 

choices2=[ 
'naughty list', 
'nice list' 
] 

choices3=[ 
'merry xmas anyhoooo!', 
'cannot win them all!', 
'have fun dude!', 
'man\'s not got?', 
] 

choices4=[ 
'must have been when you pushed the granny over', 
'could have been that cookie you stole?!', 
'probably because you were cheeky to a teacher' 
] 

choices5=[ 
'must be because you are an angel', 
'must be because you keep your room tidy', 
'Santa just never saw you' 
] 
while True: 
    input('\npress enter to check who is on the list') 
    print('checking...') 
    time.sleep(2) 
    print(random.choice(choice)) 
    time.sleep(2) 

    print(random.choice(choices2)) 
    if random.choice =='naughty list': 
     print(random.choice(choices4)) 
    elif choices2=='nice list': 
     print(random.choice(choices5)) 
    else: 
     print('wrong') 
    time.sleep(2) 
    print(random.choice(choices3)) 

答えて

0

コードの更新:また

import random, time # allowing use of random and delays 
choice1=[ 
'eddie', 
'dan', 
'erin', 
'josh', 
] 

choices2=[ 
'naughty list', 
'nice list' 
] 

choices3=[ 
'merry xmas anyhoooo!', 
'cannot win them all!', 
'have fun dude!', 
'man\'s not got?', 
] 

choices4=[ 
'must have been when you pushed the granny over', 
'could have been that cookie you stole?!', 
'probably because you were cheeky to a teacher' 
] 

choices5=[ 
'must be because you are an angel', 
'must be because you keep your room tidy', 
'Santa just never saw you' 
] 
while True: 
    input('\npress enter to check who is on the list') 
    print('checking...') 
    time.sleep(2) 
    print(random.choice(choice1)) 
    time.sleep(2) 

    list1 = random.choice(choices2) 
    print(list1) 
    if list1 =='naughty list': 
     print(random.choice(choices4)) 
    elif list1=='nice list': 
     print(random.choice(choices5)) 
    else: 
     print('wrong') 
    time.sleep(2) 
    print(random.choice(choices3)) 

を、選択はランダム関数によって内部的に使用されているので、

+0

完璧な理にかなっているのchoice1するリスト名を変更し、あなたに感謝! – user3631273

+0

それがあなたを助けたら答えを受け入れてください:) –

+0

私はこれを行う方法がわかりません:-( – user3631273

関連する問題