Ask Question
17 February, 07:41

Write a python script 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.

+4
Answers (1)
  1. 17 February, 09:26
    0
    Following are the program in the Python Programming Language.

    #import the random package to generate random number

    import random

    #declare variables and initialize to 10 and 0

    num = 10

    count=0

    #set for loop

    for i in range (1, num):

    #set variable that store random number

    n = random. randint (0,5);

    #set if conditional statement

    if (n==4):

    #print count and break loop

    print ("Count:%d"% (count))

    break

    #increament in count by 1

    count+=1;

    Output:

    Count:4

    Explanation:

    Following are the description of the program.

    Firstly, import required packages and set two variable 'num' initialize to 10 and 'count' initialize to '0'. Set the for loop that iterates from 1 to 9 and inside it, set variable 'n' that store the random number, set if conditional statement inside it print the count and break the loop and increment in count by 1.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a python script that uses random to generate a random grade (4.00 grading scale) inside a loop, and that loop keeps running until it ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers