Question

In python how would you write this to a file for example here the example output...

In python how would you write this to a file for example

here the example output to be written to a file as and i want to use a LIST

0 < 20

20 < 40

40 < 60

60 < 80

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pleas find the code below. Refer to the comments for clarification.

Code:

a=[0,20,40,60,80] #defining the list

f=open("test.txt",'w') #you can change the name of the file to any name you want

for i in range(len(a)-1):
f.write(str(a[i])+"<"+str(a[i+1])+"\n") #printing in file

f.close() #closing the file

Do give a thumbs up if you are satisfied with the answer to help me out. Thanks! :)

Add a comment
Know the answer?
Add Answer to:
In python how would you write this to a file for example here the example output...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use Python for this program Random Number File Writer Write a program that writes a...

    Please use Python for this program Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range 1 through 500. The program should let the user specify how many random numbers to put into the file. The name of the file to write to should be 'random.txt'. Submit the random.txt file generated by your program with the assignment. Sample program execution: Python 3.4.3 Shell Eile Edit...

  • ( Python Program) explain how Input/Output data files work in a Python program, and how you...

    ( Python Program) explain how Input/Output data files work in a Python program, and how you would use a loop to process input and/or output. Define the differences in a field, record and file, and define what an exception is.

  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • // use "for i in range(): //use len. //basic python //discrete mathematics Write a program in...

    // use "for i in range(): //use len. //basic python //discrete mathematics Write a program in Python (in a .py file) that: Makes two lists of 50 numbers each, where the first list is multiples of 5, and the second list is the first 50 squares: 1, 4, 9, 16, 25, 36, ....up to 2500. then I want you to make a third list by multiplying each individual pair in the two lists, so for example: 5 times 1 is...

  • Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt...

    Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt formatted like this:      Tuesday we have Joe McHungry and Paul McHungry Wednesday we have Cindy Johnston and Paul Paulsen Thursday we have Amin Mirzaei and Atefeh Mirzaei gets turned into that: The McHungry on Tuesday Cindy and Paul on Wednesday The Mirzaei on Thursday 2)Write a script that takes as argument a port number. It returns the next port that is not assigned to...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • I have a text file and want to rank entities by occurrences and output to a text file in the foll...

    I have a text file and want to rank entities by occurrences and output to a text file in the following format: e.g. Bob TAB person TAB 120 Scotland TAB location TAB 105 George TAB person TAB 83 After this I want to rank the co-occurrence (in a sentence) of the top 10 entity pairs and write to a text file: Bob TAB George TAB 20 Scotland TAB Bob TAB 15 etc... How do I do this in python?

  • Python question When reading and writing into a file. Say i want to read in input...

    Python question When reading and writing into a file. Say i want to read in input using a file called input.txt and then do something. Then i want to output the results to an additional file called output.txt. i have seen ouput.out or results.out used and not .txt. What is the difference? When would you use .out and not .txt? thank you

  • I have a text file and want to rank entities by occurrences and output to a...

    I have a text file and want to rank entities by occurrences and output to a text file in the following format: e.g. Bob TAB person TAB 120 Scotland TAB location TAB 105 George TAB person TAB 83 After this I want to rank the co-occurrence (in a sentence) of the top 10 entity pairs and write to a text file: Bob TAB George TAB 20 Scotland TAB Bob TAB 15 etc... How do I do this in python?

  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','b' :'#,, etc ) Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol e, and so forth. The program should open a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT