mardi 5 mai 2020

python random() big numbers decimal

how would we approach to make this work? i kinda understand the error string can not be converted to float/int so yeahh ps sorry this is my first time programming blah blah and using this site stackoverflow is amazing tho

.....

import random
import secrets
def no_of_shuffles():

    secret_list2 = secrets.SystemRandom()
    user = 2#input("just fucking type")
    rrr = random.random()#generate a random decimal
    print(rrr)
    sss =    rrr*float(user)#coming up with new number by muliplying the generated no. with the user input
    print(sss)
    cts = str(sss)#conversion to string to create a list for removing the decimal point and "0
    print(sss)
    newlist=[x for x in cts[2:]]#creating a list from float without the "decimal point" and "0"
    print(newlist)
    newlist=[float(i) for i in newlist]
    newlist= list(map(int, newlist))#converting the string elements in list to integer
    num1= secret_list2.choice(newlist)#random choice from the new created list
    print(newlist)
    print(str(num1)+' num 1')
    shuffle = secret_list2.choice(newlist)
    for x in range(shuffle):
        (random.shuffle(newlist))
    shit = secret_list2.choice(newlist)
    print(str(shit)+' shit')
    print(str(shuffle)+' shuffle')
    second_term = (((user*(shuffle+1))-(shit))+1)+random.randint(1, 77)
    if second_term < 0 or second_term < shuffle+1:
        second_term = random.randint(7,777)
    print(str(second_term)+' second term')
    #condition for num1 is 0
    if num1 == 0:#when the num1 random selection is 0
    #makes a new random choice from list
        when_num1_is_zero = secret_list2.choice(newlist)
        if when_num1_is_zero == 0:# if the new choice is also 0
            print(0)
        else:
            print(random.randint((shuffle + 1), second_term))
    else:
        print(random.randint((shuffle+1),second_term))

for x in range(100000):
    print(no_of_shuffles())

.......enter image description here




Aucun commentaire:

Enregistrer un commentaire