Skip to main content
edited body
Source Link
Jacques Gaudin
  • 17.1k
  • 11
  • 59
  • 80

You are choosing a random string, printing it, then choosing another string and compare it to "1"!

Each time you call random.choice(rownum1), you will get a new randonrandom string. The correct way to do what you want is to store the random string in a variable:

import random rownum1 = ["1","2","3","4","5","6","7","8","9"] num = random.choice(rownum1) # <- store the value in a variable for later reuse print(num) if num == "1": del rownum1[0] print(rownum1) 

You are choosing a random string, printing it, then choosing another string and compare it to "1"!

Each time you call random.choice(rownum1), you will get a new randon string. The correct way to do what you want is to store the random string in a variable:

import random rownum1 = ["1","2","3","4","5","6","7","8","9"] num = random.choice(rownum1) # <- store the value in a variable for later reuse print(num) if num == "1": del rownum1[0] print(rownum1) 

You are choosing a random string, printing it, then choosing another string and compare it to "1"!

Each time you call random.choice(rownum1), you will get a new random string. The correct way to do what you want is to store the random string in a variable:

import random rownum1 = ["1","2","3","4","5","6","7","8","9"] num = random.choice(rownum1) # <- store the value in a variable for later reuse print(num) if num == "1": del rownum1[0] print(rownum1) 
Source Link
Jacques Gaudin
  • 17.1k
  • 11
  • 59
  • 80

You are choosing a random string, printing it, then choosing another string and compare it to "1"!

Each time you call random.choice(rownum1), you will get a new randon string. The correct way to do what you want is to store the random string in a variable:

import random rownum1 = ["1","2","3","4","5","6","7","8","9"] num = random.choice(rownum1) # <- store the value in a variable for later reuse print(num) if num == "1": del rownum1[0] print(rownum1)