1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nekit [7.7K]
3 years ago
8

Write code that does the following: opens an output file with the filename number_list.txt, uses a loop to write the numbers 1 t

hrough 100 to the file, then closes the file.
Computers and Technology
1 answer:
Lady_Fox [76]3 years ago
8 0

Answer:

# create the file

filename = "Testfile.txt"

# for writing, we create the output file:

outPutfile = open(filename, "w")

# Writing numbers from 1-100

for item in range(1,101):

 outPutfile.write((str)(item))

outPutfile.close()

# printing the contents to verify it worked correctly

infile = open(filename, "r") #note the "r" indicates the mode

fileContents = infile.read()

infile.close()

print(fileContents)

Explanation:

  • Define the working file fileName = TestFile
  • Create the output file for writting outPutfile = open(filename, "w")
  • Use a for loop to write numbers from 1-100 to the file outPutfile.write((str)(item))
  • Close the file outPutfile.close()
  • You may open the file read its content and print the contents to verify it worked correctly
You might be interested in
In order for a fault-block mountain to form, a ______ must take place along a fault line and one side must be ________.
Sav [38]
I think the correct answer from the choices listed above is the first option. In order for a fault-block mountain to form, a shift must take place along a fault line and one side must be elevated. Fault-block mountains form<span> when Earth's crust pushes material up and down near a </span>fault line<span>. Hope this answers the question.</span>
7 0
3 years ago
List two types of energy sources
makvit [3.9K]

Answer:

Types of energy sources include;

  • Geothermal energy
  • Solar energy
  • Wind power
  • Nuclear energy
  • Hydropower
  • Coal burning
  • Natural gas
  • Biomass energy
8 0
3 years ago
Read 2 more answers
A transcript must bear a(n)___ to be considered official
harkovskaia [24]
A transcript must have a signature or school stamp. 
7 0
3 years ago
Read 2 more answers
Tfuuvj vjiibjoon Ghosh kpj
Nookie1986 [14]

Answer: A

Explanation: For any formal document you need your major points.

5 0
3 years ago
Read 2 more answers
Averigua las diferentes intensidades, la potencia total y el gasto en € (de un mes de 30 días con el equipo conectado todo el ti
Naily [24]

<u>Explanation</u>:

<u>Here's what the question entails in clearer detail;</u>

Find out the different intensities, the total power and the cost in € (from a 30-day month with the equipment connected all the time) in the following case: Component Voltage (V) Power (P) CPU 0.95 V 27.97 W RAM 1,257 V 2.96 W Graphics Card 3.28 V 75.3 W HDD 5.02 V 19.3 W Fans 12.02 V 2.48 W Motherboard 3.41 V 18.3 W

7 0
3 years ago
Other questions:
  • "what is the #1 resource used when researching a product online?"
    5·1 answer
  • Ned and mary ann are saving their files to a cd
    15·1 answer
  • What is the radix transformation method?
    5·1 answer
  • Select the correct answer.
    6·1 answer
  • A network technician is designing a network for a small company. The network technician needs to implement an email server and w
    7·1 answer
  • Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The fi
    15·1 answer
  • Decimal numbers is equivalent to binary 110
    5·1 answer
  • Why does it keep saying this when I’m putting my right credit card number
    6·1 answer
  • 2. what are the advantages of breaking up a single logical message into a number of fixed-sized packets and then sending each on
    5·1 answer
  • What kind of AR target category makes sense for a playing card with a picture on it?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!