Ask 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 generates a 4.00 GPA.

+1
Answers (1)
  1. 1 October, 13:23
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers