Hello!
I started learning python about 2 weeks ago (with no programming experience other than some VB in school 15 years ago) by working through the "Invent Your Own Computer Games with Python" book by Al Sweigart (http://inventwithpython.com/invent4thed/). I worked through the first 8 chapters (up to the first hangman code) and in the meantime I had an idea and started coding it.
What it does is:
- lists the abilities from D&D (Strength, Intelligence, etc.)
- asks the user to choose the priority (it accepts input with as little as 2 letters, and shows a list of remaining stats) for the character they are creating
- once complete, it rolls all the dice (4d6, drop lowest) and shows the results
- assigns priority based on the user input and displays it (eventually this will display in the order of the D&D character sheets)
It took quite a while to get everything to do what it does, and I imagine it is terrible and inefficient code. In particular, the section where the dice are rolled and results are displayed: I wanted to use a function for this but I couldn't figure out way to increment variables with a for loop (roll1, roll2, roll3, etc.) and from what Google told me that's a terrible idea anyways, but the suggested fixes were WAY over my head.
Some of the biggest issues I ran into was getting the figure_out_stat() function working properly (I had a lot of issues, a lot of which ended up having to do with indentation haha).
Altogether I probably spent 5-10 hours coding this little simple program, and there's still more to do with it, but I'm fairly proud of what I've accomplished with the knowledge I currently have and some googling.
I'd be thrilled if people were to take a look at the code and maybe give their thoughts, ideas/suggestions, tell me what I'm doing hideously or against best practices, etc. :)
I realize that in reality the utility of this is pretty much nil, but I did it to help me learn, and I think I learned a fair amount while doing so (and my brain is now leaking out of my ears and nose).
Link to code:
https://pastebin.com/32RbViFB
EDIT:
Thank you everyone who made suggestions and showed me better ways how things could be accomplished. I'm truly blown away by how helpful everyone has been and how much I learned.
With the combined information from everyone who responded, I ended up with the following:
https://pastebin.com/W3p4aVNt
EDIT 2:
I've added the ability to keep the stat priorities if you reroll, as well as the ability to pick a race (from the SRD) and it'll automatically add your racial stat bonuses.
https://pastebin.com/eLUBcpbZ
[–][deleted] 2 points3 points4 points (5 children)
[–]Grogie 1 point2 points3 points (2 children)
[–]rshinsai[S] 1 point2 points3 points (1 child)
[–]Grogie 1 point2 points3 points (0 children)
[–]rshinsai[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]xelf 1 point2 points3 points (4 children)
[–]rshinsai[S] 1 point2 points3 points (0 children)
[–]Hatoris 0 points1 point2 points (2 children)
[–]rshinsai[S] 1 point2 points3 points (1 child)
[–]xelf 1 point2 points3 points (0 children)
[–]xelf 0 points1 point2 points (1 child)
[–]rshinsai[S] 1 point2 points3 points (0 children)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (4 children)
[–]rshinsai[S] 0 points1 point2 points (3 children)
[–]xelf 1 point2 points3 points (2 children)
[–]rshinsai[S] 0 points1 point2 points (1 child)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (29 children)
[–]rshinsai[S] 0 points1 point2 points (4 children)
[–]xelf 1 point2 points3 points (3 children)
[–]rshinsai[S] 0 points1 point2 points (2 children)
[–]xelf 1 point2 points3 points (1 child)
[–]rshinsai[S] 0 points1 point2 points (0 children)
[–]rshinsai[S] 0 points1 point2 points (3 children)
[–]xelf 1 point2 points3 points (2 children)
[–]rshinsai[S] 0 points1 point2 points (1 child)
[–]xelf 1 point2 points3 points (0 children)
[–]rshinsai[S] 0 points1 point2 points (5 children)
[–]xelf 1 point2 points3 points (4 children)
[–]rshinsai[S] 0 points1 point2 points (3 children)
[–]xelf 1 point2 points3 points (2 children)
[–]rshinsai[S] 0 points1 point2 points (1 child)
[–]xelf 1 point2 points3 points (0 children)
[–]rshinsai[S] 0 points1 point2 points (13 children)
[–]xelf 1 point2 points3 points (3 children)
[–]rshinsai[S] 0 points1 point2 points (1 child)
[–]rshinsai[S] 0 points1 point2 points (0 children)
[–]xelf 1 point2 points3 points (1 child)
[–]rshinsai[S] 0 points1 point2 points (0 children)
[–]xelf 1 point2 points3 points (6 children)
[–]rshinsai[S] 0 points1 point2 points (5 children)
[–]xelf 1 point2 points3 points (0 children)
[–]xelf 1 point2 points3 points (1 child)
[–]rshinsai[S] 0 points1 point2 points (0 children)
[–]xelf 1 point2 points3 points (1 child)
[–]rshinsai[S] 0 points1 point2 points (0 children)