How to remove a number from a list that has a range between two numbers? [closed]

2024/9/22 4:18:50

I am trying to take a random number from a list that goes from 0 to 9999. When I get that number, I want to compare it to a 4 digit number. Then, if it doesn't work, I want to REMOVE that random number from the list of 0 to 9999 e.g. it picks 9999 randomly and it compares to 3129 so it deletes it from the list and tries again list (range (0000, 9998))

lis = list(range(0000,9999))
import random
num = random.choice(lis)
while int(num) < pin or int(num) > pin:print(num)num = random.choice(lis)count = count + 1lis = lis.remove(num)
print('Got your pin in ' + str(count))
from time import sleep
sleep(4)
Answer
 lis = lis.remove(num) 

will set your list to 'None' because the remove method does not return anything. So just using

 lis.remove(num) 

might solve your problem - whatever your problem is. Your post doesn't really contain a clear question.

https://en.xdnf.cn/q/119171.html

Related Q&A

How do I solve an attribute error?

So like I said before my code (Or my current project that I am working on) is riddled with errors. So far I have at least solved a dozen errors or more and honestly I just give up. I mean God knows how…

Two variables in Django URL

I want a URL something like this:/(category)/(post-slug)On the link this is what I have:{% url blog.category blog.slug %}and for the url.py:url(r^(I DON"T KNOW WHAT TO PUT ON THIS PART TO GET THE …

Python 3.2 Replace all words in a text document that are a certain length?

I need to replace all words in a text document that are of length 4 with a different word. For example, if a text document contained the phrase "I like to eat very hot soup" the words "l…

Python split list at zeros [duplicate]

This question already has answers here:Closed 11 years ago.Possible Duplicate:Remove leading and trailing zeros from multidimensional list in Python if I have a list such as:my_list = [[1,2,0,1], [1,0…

Creating Dynamic Text Using the blit method [duplicate]

This question already has answers here:How to display text with font and color using pygame?(7 answers)Closed last year.Im creating a basic game where a black square moves around the screen. There are…

Regex to match special list items

I have weird list of items and lists like this with | as a delimiters and [[ ]] as a parenthesis. It looks like this:| item1 | item2 | item3 | Ulist1[[ | item4 | item5 | Ulist2[[ | item6 | item7 ]] | i…

How to choose the best model dynamically using python

Here is my code im building 6 models and i am getting accuracy in that, how do i choose that dynamically which accuracy is greater and i want to execute only that model which as highest accuracy."…

How do you access specific elements from the nested lists

I am trying to access elements from the nested lists. For example, file = [[“Name”,”Age”,”Medal”,”Location”],[“Jack”,”31”,”Gold”,”China”],[“Jim”,”29”,”Silver”,”US”]]This data c…

Why does BLOCKCHAIN.COM API only return recipient BASE58 addresses and omits BECH32s?

Following this post, I am trying to access all transactions within the #630873 block in the bitcoin blockchain.import requestsr = requests.get(https://blockchain.info/block-height/630873?format=json) …

rename columns according to list

I have 3 lists of data frames and I want to add a suffix to each column according to whether it belongs to a certain list of data frames. its all in order, so the first item in the suffix list should b…