Python random character + number extraction

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

Hello, I am a student who studies Python hard these days.

It can be a random number or a random text, but I'm writing a question because I think I need a tip to go to the advanced stage by mixing it.

import random
import string

print(''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(100)))

If you do this

IH58VBFL59HAX0HVGCRVVWDZC6MW6PVCL8H6NJYQVBC6LDVZB4DESRN5YYWVU8OJ8AP3SSCRS5JG225UE6TWZITDHY9AL2M6H7FB

It's printed like this.

What I want to do is

Please give us some tips.

python

2022-09-20 11:36

1 Answers

Number one is really easy. Do range(98) and put IH at the front. Wow! Boksepyunsal

You have to think about number two.
Now, when you get a random string, it's being randomized out of all the capital letters and numbers.
How does that happen?
Is it because of string.ascii_uppercase and string.digits in random.choice(string.ascii_uppercase+string.digits)?
No matter how much you read the code, only string.ascii_uppercase seems to be related to capital letters, and only string.digits seems to be related to numbers.
But what is this in the first place?
Shall we check?

import string
print(string.ascii_uppercase)
print(string.digits)

Hmm... So random.choice('Ganada') is the function of selecting something that exists in any order in the string ?
Then... If you want to randomly choose between 0, 1, 2, 3, 4, 5, 6, a, b, c, d, e, and f, what should you put in the random.choice(???)?
Will this mystery be solved?
It's time to wake up to your hidden coding skills!!! Try it yourself.

PS. There is no concept of "last" in randomization. If you have to say, the last one is the last one to appear when you sort out the number of possible cases, and that's probably IHFFFFFF...It should be . Most ascending sortings have numbers going forward and alphabets going backward.


2022-09-20 11:36

If you have any answers or tips


© 2022 pinfo. All rights reserved.