Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

User Input to set dynamic variable Python

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try changing:

  zorluk_secimi == kolay
  zorluk_secimi  == orta
  zorluk_secimi == zor

respectively to:

  zorluk_secimi == 'kolay'
  zorluk_secimi  == 'orta'
  zorluk_secimi == 'zor'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading