Generation

generate functionWed, 14 Jun 2023

Takes a number input from a text box named "outof" and a number input from a text box named "chance" and internally randomly generates between two number outputs "1" and "2" when a button named "Start" is clicked. The number input from the text box "chance" is the amount of times a generation will loop. The number input from the text box "outof" is how many times a single generation has to generate a 100% line of "number output "1". If a single generation results in all randomly generated numbers resulting in "1", the loop ends and a banner that says "100% success!" appears and shows how many time the function looped before resulting in a success. If the number "1" is generated, the word "Success" is printed to output "Result" and if the number "2" is generated, the word "Fail" is printed to "Result". the printed words "Success" and "Fail" are printed in a row spaced by commas.

def start(chance, outof): for i in range(chance): for x in range(outof): if random.randint(1,2) == 1: print("Success") else: print("Fail") print("100% Success!")

Questions about programming?Chat with your personal AI assistant