-2

I'm fairly new to python and am doing some basic code. I need to know if i can repeat my iteration if the answer is not yes or no. Here is the code (sorry to those of you that think that im doing bad habits). I need the iteration to repeat during else. (The function just outputs text at the moment)

    if remove_char1_attr1 = 'yes':
        char1_attr1.remove(min(char1_attr1))
        char1_attr1_5 = random.randint(1,6)
        char1_attr1.append(char1_attr1_5)
        print("The numbers are now as follows: " +char1_attr1 )
    elif remove_char1_attr1 = 'no'
        break
    else:
        incorrect_response()
ddoGas
  • 831
  • 6
  • 17

2 Answers2

1

Just put the code into a loop:

while True: 
    if remove_char1_attr1 = 'yes':
        char1_attr1.remove(min(char1_attr1))
        char1_attr1_5 = random.randint(1,6)
        char1_attr1.append(char1_attr1_5)
        print("The numbers are now as follows: " +char1_attr1 )
    elif remove_char1_attr1 = 'no'
        break
    else:
        #incorrect_response()
        print("Incorrect")

then it will run till the remove_char1_attr1 is "no"

6502
  • 108,604
  • 15
  • 155
  • 257
Sven
  • 790
  • 7
  • 22
0

You can try looping while it's not yes or no

while remove_char1_attr1 not in ('yes', 'no'):    
    if remove_char1_attr1 = 'yes':
        char1_attr1.remove(min(char1_attr1))
        char1_attr1_5 = random.randint(1,6)
        char1_attr1.append(char1_attr1_5)
        print("The numbers are now as follows: " +char1_attr1 )
    elif remove_char1_attr1 = 'no'
        break
    else:
        incorrect_response()
JaviOverflow
  • 1,299
  • 1
  • 12
  • 28