I'm trying to learn Python and this is my fist functioning little bit I wrote for a campaign I'm doing in D&D. I was wondering if I was doing anything wrong or if anyone had tips on how to make it more readable, function smoother, or be more interactive.
from random import randint
spells = '''Rol
#A LOT OF TEXT FROM HERE
I copied this part from roll20 website list of spells then just broke it up biased on the line breaks.
#to here...
'''
spells=spells.split('''\n\n''')
for i in [348, 332, 315, 294, 262, 224, 192, 149, 94, 44, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]:
del spells[i]
def ask():
print('"So ya done goofed I see, usin magic where there not be, I have your roll and the spell out of control, just tell me what you need!"')
while True:
print()
print('if you need a random spell type random or r, if you need a specific spell enter a number from 1 to '+str(len(spells)))
need=input()
if need.isdigit():
need=int(need)
if need > len(spells) :
print('"THERES NOT THAT MANY SPELLS YE TROLLUP"')
elif need<1:
print('"thee list start at ONE ye trollup"')
else:
print(spells[need-1])
elif need.lower().startswith('r'):
need=randint(0,len(spells)+1)
need=need-1
print(spells[need])
else:
print('FOLLOW MY INSTRUCTS WITH INTIGER OR RANDOM YE GOD FEARING REBEL')
ask()
Also, to get that fun little list that I made to get rid of useless strings in my spells
list, I went ahead and wrote this:
guess=0
correctGuess=[]
for i in spells:
if len(i)<15: #because I knew the strings I wanted to remove were under 15 in length
print(i)
x=i
while x != spells[guess]:
guess=guess+1
if x==spells[guess]:
print('That spell is '+str(guess))
correctGuess.append(guess)
#reversed list so that when it removes the specific threads it isn't changing the length that the next thread to be removed is at
revCorrectGuess=list(reversed(correctGuess))
Then I manually copied the output list and took out the bit to make my code a little shorter.