+ 7
How can I print random numbers or charecters to the screen ?
hi everyone! I had a simple doubt with you. how can I print random numbers or charecters to the screen ? I even searched in Google but I could not understand it . any help would be greatly appreciated. thank you!
8 Respostas
+ 8
Thanks a lot ~ swim ~ and HonFu [#GoGetThatBugChamp!]☺
+ 6
Thanks ~ swim ~ ☺
+ 6
Thanks a lot Jordi de Pelseneer
+ 5
I think I forgot that it was there
+ 5
Anyway thanks
+ 5
but how can I do it if I want to provide the numbers or charecters ?
+ 3
For example you can use random.randint in combination with the built-in function chr().
First you look up the ASCII table on the www, then you figure out which numbers the letters you want have.
And then you generate an int with randint using your range of letters as the borders of the range, and you transform the result into a letter with chr.
There are other ways as well.
Use Google with what I said, try to figure it out, you'll make it. 😉
+ 1
if i understand your question correctly.
u need to import the 'random' librairy.
Easy way to print random numbers, i using a for loop
for example;
for i in range(1):
print(random.randint(1,100)
this will print a random number between 1 and 100.
For random Characters, you can use ASCII, or just make a list with all the letters in it and loop trough it randomly.