Ask Question
15 January, 08:42

Write a script that will generate random integers in the range from

0 to 50, and print them, until one is finally generated that is greater

than 25. The script should print how many attempts it took.

+3
Answers (1)
  1. 15 January, 12:40
    0
    Let's do this in Python, we shall use the package random to generate a random double between 0 and 1. Then we multiply it with 50 and covert to integer to get a random integer between 0 and 50. Place a While function with condition to stop when it's greater than 25

    from random import random

    attempts = 1

    random_int = int (random () * 50)

    print (random_int)

    print ("This is attempt " + attempts)

    while random_int < = 25:

    attempts + = 1

    random_int = int (random () * 50)

    print (random_int)

    print ("This is attempt " + attempts)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a script that will generate random integers in the range from 0 to 50, and print them, until one is finally generated that is greater ...” 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