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
What is the most useful advantage of using the Slide Sorter view to rearrange slides instead of using the slide thumbnails in No
Eddi Din [679]
<span>b. In Slide Sorter view, the user can zoom in to read text on slides more easily or zoom out to see more of the presentation’s slides at once.
Moreover, in Normal View, the number of slides that you can see together at once is quite less, so it is more advantageous to use the Slide Sorter View to sort your slides
</span>
5 0
3 years ago
PLS HELP) Early word processors ran on devices that looked like digital _______?
stealth61 [152]
I looked it up it just says true
8 0
3 years ago
Read 2 more answers
The mean life of a certain computer hard disk in continual use is 8 years. (a) How long a warranty should be offered if the vend
Allushta [10]

Answer:

a) 0.843 years

b) 1.785 years

Explanation:

See attached pictures for detailed explanation.

4 0
3 years ago
Security measures are sometimes described as a combination of physical, technical, and administrative (PTA) safeguards. Which of
attashe74 [19]

Answer:

Measures including device data encryption, anti-malware software, and communications encryption.

6 0
3 years ago
Explain how a message is transmitted from one computer to another using layers.
nevsk [136]
I need some answer chouices but they use iphones
7 0
3 years ago
Other questions:
  • An international magazine publisher has commissioned you to do a series of images in black and white. The publisher distributes
    13·1 answer
  • You are using a crimper to attach an RJ-45 connector to a Cat 6 UTP cable. You need to use the T568A standard to connect the ind
    6·1 answer
  • If you want to use your computer for recording your band, you would benefit most from a(n)
    13·2 answers
  • what is the primary way to access applications in windows 8? a. control panel b. start menu c. desktop tiles d. context menu
    7·1 answer
  • How to send an email
    7·2 answers
  • Write a destructor for the CarCounter class that outputs the following. End with newline.
    9·1 answer
  • "in program arrays12.java a swap method is called. does the swap method exchange parameter values x and y?"
    11·1 answer
  • When you are working in Performance Monitor, in the "Add Counters" dialog box, and need more information about a particular coun
    8·1 answer
  • WHO SAYS BUP ALL THE TIME ​
    8·1 answer
  • There are many commercially made household linens found in the?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!