I made a simple random.choice code by myself. But there is a major problem with it. I can’t take user input to dynamically set variables.
import pygame import pygame_menu import random kolay_secim = ["agac","odun","baba"] orta_secim = ["zar","okey","tavla"] zor_secim = ["emekli","yasli","deli"] zorluk_secimi=input('Hangi zorlukta oynamak istiyorsunuz? (kolay,orta,zor)') if zorluk_secimi == kolay : print(random.choice(kolay_secim)) elif zorluk_secimi == orta : print(random.choice(orta_secim)) elif zorluk_secimi == zor : print(random.choice(zor_secim)) else: print("Gecersiz Zorluk Secimi yazima dikkat ediniz.")
What I’m trying to achieve is taking a user input and setting that as zorluk_secimi and after that if it matches to a category it will pick a random word from that category.
Advertisement
Answer
Try changing:
zorluk_secimi == kolay zorluk_secimi == orta zorluk_secimi == zor
respectively to:
zorluk_secimi == 'kolay' zorluk_secimi == 'orta' zorluk_secimi == 'zor'