Im creating a word jumble game and im getting an issue where it says my while loop is empty i could really use with some help heres my code thanks.
import random
count = 0
word = 'index'
wordLength = (5)
print('the word is', word ,'\n')
high = len(word)
low = -len(word)
for i in range(15):
position = random.randrange(low, high)
listf = [0,1,2,3,4]
randomletter = random.choice(listf)
for each in range(wordLength):
while count < 6:
if randomletter == 0:
listf.remove(0)
randomletter = random.choice(listf)
print(word[0])
elif randomletter == 1:
print(word[1])
listf.remove(1)
randomletter = random.choice(listf)
elif randomletter == 2:
print(word[2])
listf.remove(2)
randomletter = random.choice(listf)
elif randomletter == 3:
print(word[3])
listf.remove(3)
randomletter = random.choice(listf)
elif randomletter == 4:
print(word[4])
listf.remove(4)
randomletter = random.choice(listf)
count += 1
inputs = input('press enter to exit')
Here is the error i get :
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/random.py", line 253, in choice
i = self._randbelow(len(seq))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/random.py", line 230, in _randbelow
r = getrandbits(k) # 0 <= r < 2**k
ValueError: number of bits must be greater than zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Volumes/sec.student/Y9/Y9B/Oliver McLean/jumbler2.0.py", line 43, in <module>
randomletter = random.choice(listf)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/random.py", line 255, in choice
raise IndexError('Cannot choose from an empty sequence')
IndexError: Cannot choose from an empty sequence
Aucun commentaire:
Enregistrer un commentaire