Python Forum
how to avoid a lot of 'if' statments ?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to avoid a lot of 'if' statments ?
#1
politics_dict = {'Ляшко': '1', 'Порошенко': '2', 'Яценюк': '3', 'Тимошенко': '4'}


pol1 = (str(input('Хто буде бити ? (Виберіть цифру)\n')))
pol2 = (str(input('Кого будуть бити ? (Виберіть цифру\n')))

if pol1 == '2' and pol2 == '1':
    print(poroh.attack(lyashko))
elif pol1 == '2' and pol2 == '3':
    poroh.attack(yacenyuk)
elif pol1 == '2' and pol2 == '4':
    poroh.attack(tymoshenko)
Im making a game and I don`t know how to avoid theese if, elif statments, is there a way to not write a huge code ?
Reply


Messages In This Thread
how to avoid a lot of 'if' statments ? - by witch - Aug-27-2018, 11:36 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020