Reputation: 227
I have created this code to get 3 different options in 3 different places. Its actually a flash card program i hoped to get working but I can't. It goes into a endless loop and i have no idea why. There may also be other problems but i havent got to them yet but please tell me anyway. Keep the sam var names so i can understand easily. I have attached all the code. They is some more but its not been implemented yet.
There is also 3 lists each with 14 items but these won't go into code:
key_words = ['Cellulose', 'Respiration', 'Haemoglobin', 'Ventilation', 'Cartilage', 'Cytoplasm', 'Nucleus', 'Alveoli', 'Amino acids', 'Virus', 'White blood cells', 'Photosynthesis', 'Stomata', 'Vaccine', 'Fibre']
defs = ['Tough substance that makes up the cell walls of green plants', 'A chemical reaction that causes energy to be released from glucose', 'A substance which joins to oxygen and carries it round the body in the blood', 'Breathing', 'Tough, smooth substance covering the ends of bones to protect them', 'Jelly-like part of a cell where chemical reactions happen', 'Controls what happens inside a cell', 'Tiny air sacs in the lungs', 'Produced when proteins are digested', 'The smallest type of microbe', 'Can engulf bacteria or make antibodies', 'The process of turning carbon dioxide, water and light into glucose and oxygen', 'Small holes in the underside of a leaf', 'Dead or inactive forms of a microorganism', 'A nutrient that cannot be digested']
completed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
thanks Callum
import random
option1 = random.randint(int(1), int(14))
option2 = random.randint(int(1), int(14))
option3 = random.randint(int(1), int(14))
while option1 == option2 or option1 == option3:
placement1 = random.randint(int(1), int(3))
while option2 == option3:
option2 = random.randint(int(1), int(3))
placement1 = random.randint(int(1), int(3))
placement2 = random.randint(int(1), int(3))
placement3 = random.randint(int(1), int(3))
while placement1 == placement2 or placement1 == placement3:
placement1 = random.randint(int(1), int(3))
while placement2 == placement1 or placement2 == placement3:
placement3 = random.randint(int(1), int(3))
print('What is the correct defenition for', key_words[option3])
place3 = 1
if placement1 == 1:
print('1: ', defs[option1])
elif placement1 == 2:
print('1: ', defs[option2])
elif placement1 == 3:
print('1: ', defs[option3])
place3 = '1'
if placement2 == 1:
print('2: ', defs[option1])
elif placement2 == 2:
print('2: ', defs[option2])
elif placement2 == 3:
print('2: ', defs[option3])
place3 = '2'
if placement3 == 1:
print('3: ', defs[option1])
elif placement3 == 2:
print('3: ', defs[option2])
elif placement3 == 3:
print('3: ', defs[option3])
place3 = '3'
choice = str(input('Enter 1, 2 or 3: '))
if choice == place3:
print('Well done, correct.')
a = completed[option3] + 1
completed[option3] += 1
else:
print('Inccorect. Have another look and we`ll come back later.')
Upvotes: 0
Views: 54
Reputation: 18467
You will never break out of your first loop.
while option1 == option2 or option1 == option3:
placement1 = random.randint(int(1), int(3))
The condition hinges on the values of option1, option2, and option3, which are never adjusted in the body of the loop. If the code enters the loop, it will stay there.
Incidentally, this code has numerous other serious problems and code smells. I don't have time to name them all.
Upvotes: 1
Reputation: 531858
In your first loop:
while option1 == option2 or option1 == option3:
placement1 = random.randint(int(1), int(3))
you never change the value of option1
. If the condition is true going into the loop, it will remain true forever. Did you mean to use option1
instead of placement1
?
Upvotes: 2