samedi 20 novembre 2021

Write a program that uses random to generate a random grade (4.00 grading scale) inside a loop, and that loop keeps running until it generates a 4.00 [closed]

Write a program that uses random to generate a random grade (4.00 grading scale) inside a loop, and that loop keeps running until it generates a 4.00 GPA. Once you have randomly generated a 4.00, print the number of iterations it took to randomly generate.`import random

count = 0
i = 0

while i != 4:
    i=round(random.uniform(0,4),2)
    
    if i == 4:
        break
    print(i)
    i +=1
    count += 1

print("It took {:d} iterations to get 4.00".format(count))



Aucun commentaire:

Enregistrer un commentaire