79.6k views
2 votes
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.

User Pizzaboy
by
5.4k points

1 Answer

7 votes

Answer:

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

Step-by-step 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.
User Terrylynch
by
5.5k points