Jan-29-2017, 08:34 PM
(This post was last modified: Jan-29-2017, 08:34 PM by ichabod801.)
First, I would suggest checking out this tutorial. Doing a text adventure is a common thing new Python programmers do, but the if/elif/else structure you are using quickly becomes unwieldy. You can use the same sort of techniques shown in that tutorial for choosing the members of the gang, and simplify the code you are using quite a bit. Note that you are repeating the same pattern over and over again: "For <this role>, do you want <person 1> who is good but wants a 20% cut, or <person 2> who is not so good, but wants a 10% cut." Whenever you are repeating the same pattern over and over again, you should think about a loop. That's what loops do, they repeat the same thing. To do that, you need to take the variations, and put them in some sort of data structure. For example:
robbers = [('driver', 'good', 20, 'Chris'), ('driver', 'not so good', 10, 'Harry'), ('locksmith', 'good', 20, 'Ben'), ('locksmith', 'not so good', 10, 'Septimus'), ...] gang = [] while robbers: good = robbers.pop(0) bad = robbers.pop(0) choice = input('For your {}, do you want {} who is good and wants a 20% cut, or {} who is not so good and wants a 10% cut.'.format(good[0], good[3], bad[3]) if choice == good[3]: gang.append(good) elif choice == bad[3]: gang.append(bad)Maybe not the best solution, but it illustrates the technique I'm talking about. And once you have the gang list, it's relatively easy to do things like sum up the total cut the gang wants, print the names of the gang members, find out if the driver is good or not so good, and so on.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures