0

Is there a way to make the elif statement to a single if statement

So the elif statement is so stacked, can i make it shorter? https://code.sololearn.com/cw8i88Zj1CjE/?ref=app

10th Mar 2022, 10:00 AM
Julian Yang
Julian Yang - avatar
4 Answers
0
Nah bro. Here's my rpg, you'll find lots of those https://code.sololearn.com/cjGIfr8I4Fu2/?ref=app
10th Mar 2022, 10:10 AM
Slick
Slick - avatar
+ 1
Julian Yang here is an idea to reduce lines 50 - 78 by using a dict: wpns = {'1':ss, '2':ls, '3':hd, '4':ar, '5':pg, '6':lc, '7':ex} if shop2 in wpns.keys(): wpn = wpns[shop2] player.atk += wpn.atk player.money -= wpn.price print ('current attack' + str(player.atk)) print ('money left' + str(player.money))
10th Mar 2022, 1:21 PM
Brian
Brian - avatar
+ 1
Thanks a lot man Brian
10th Mar 2022, 1:42 PM
Julian Yang
Julian Yang - avatar
0
Thanks for answering Slick
10th Mar 2022, 10:28 AM
Julian Yang
Julian Yang - avatar