Bobcat6223 Bobcat6223
  • 27-10-2020
  • Computers and Technology
contestada

Write a script using the while loop construct that generates 100 randomly generated numbers between 0 and 99 and writes them out in a user specified filename.

Respuesta :

Cytokine
Cytokine Cytokine
  • 27-10-2020

In python:

import random

lst = ([])

i = 0

while i < 100:

   lst.append(str(random.randint(0,99)))

   i += 1

txt = " ".join(lst)

file = input("What file do you want to save your numbers to? ")

try:

   f = open(file, 'a')

   f.write(txt)

   f.close()

except FileNotFoundError:

   f = open(file, 'x')

   f.close()

   new_f = open(file, 'a')

   new_f.write(txt)

   new_f.close()

Answer Link

Otras preguntas

All chemical reactions reach chemical equilibrium unless a. there is more product than reactant. b. there is more reactant than product. c. a product is remo
Wilhelm I was declared kaiser of Germany in
Mr. Enders conducted a survey and found that of his students play a team sport and of those students play basketbal what fraction of his students play basketbal
which sentences each contain two misspelled words
Dan is thinking of a number . The quotient of this number and 1.8 is 31.5. Find dans number
Describe the 3 stages in the " life cycle" of a volcano
The midlife transition is characterized by
Mickey exercises 3/4 hour every day.How many hours does he exercises in 8 days
After World War II, why did the Soviet Union take over a number of countries to its west?
The simultaneous import and export of goods in the same industry by a particular country is known as interindustry trade. a. True b. False