Question

I need a code/ script for this problem. I am new to programming and do not...

I need a code/ script for this problem. I am new to programming and do not really know how to approach it, it may be a loop.

There is a file containing info about grocery stores A, B, C, and D. The code would split/separate the info of grocery store A alone on 1 file (AS) and all other grocery stores in another file (O).

I would like the python and Javascript version of this code please Thank you.

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

NOTE: I am writing in python programming language

code:

file = open("filename.txt","r") #opening main file
rows = file.readlines();
rows_list = []
for i in rows:
rows_list.append( i.split())
file1_text = ""
file2_text = ""

for i in rows_list:   
file1_text = file1_text+ i[0] + "\n"
del i[0]
for i in rows_list:
text2 = " "
text2 = text2.join(i)
file2_text = file2_text + text2 + "\n"
file.close()
#opening file1 ->here it creates
file1 = open("AS.txt","w")
file1.write(file1_text)
file1.close()
#opening file2 ->here it creates
file2= open("O.txt","w")
file2.write(file2_text)
file2.close()

code screenshot:

Files Output:

Add a comment
Know the answer?
Add Answer to:
I need a code/ script for this problem. I am new to programming and do not...
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 write this code in python programming and provide a screen short of the code. Reading:...

    Please write this code in python programming and provide a screen short of the code. Reading: P4E 7; Tut 7.2, 7.2.1 Upload an original Python script that satisfies the following criteria: It has at least two functions Function 1: This function has one parameter, a string containing the path to an existing text file that will be read by your function Using a with statement, the function opens the file indicated by the parameter for reading The function counts the...

  • I need help modifying this python code: a) I need to take 2 attributes of the...

    I need help modifying this python code: a) I need to take 2 attributes of the data as int - (columns (3 & 5) of my data) b) I need to take 2 more attributes as floats -(columns 4&6 of my data) c) I need to take 1 attribute as string (column 16 of my data) How would I modify this code # # Initial version - "standard programming" # # Define a list for the data. The data structure...

  • I need help with this python programming exercise, please! thanks in advance Create a Python script...

    I need help with this python programming exercise, please! thanks in advance Create a Python script file called hw4.py. Add your name at the top as a comment, along with the class name and date. Both exercises should be in this file, with a comment before each of them to mark it. Ex. 1. Write a program that inputs an integer number from the user, then prints a letter "O" in ASCII art using a width of 5 and the...

  • I am in java programming I need to // TO DO: Add a function call to...

    I am in java programming I need to // TO DO: Add a function call to the function named // findMaxSalesAndBestSellingAgent() // with 3 arguments (maxSalesDouble, totalHousePriceDouble, and // totalHousePriceDouble) // using an assignment statement form) and store the value returned by the // function // in the input variable maxSalesDouble I wrote this in the code maxSalesDouble = findMaxSalesAndBestSellingAgent(totalHousePriceDouble); Would this be correct?

  • I am new to programming (2 weeks of playing with it) I have written code for...

    I am new to programming (2 weeks of playing with it) I have written code for a timer in Visual Studio 2013. I am wondering if someone can show me how to write code/what the code would look like in a MODULE1.vb. I was thinking that for this timer I could create MsgBox using a DO UNTIL LOOP that would pop up every 20 seconds that says "hurry up!" until 1 minute has passed. As I said I am just...

  • Hello, I am attempting to write a basic shell script using bash. It will need to...

    Hello, I am attempting to write a basic shell script using bash. It will need to print the user, host, time, and date. It will need to take user input for a txt file to be searched and create a new file to save the results. It must print the number of lines and characters in the text. The user will need to enter three words to be searched, and the number of occurrences of those words in the text...

  • i need help with this homework web page and i need the code too Using the "do while" or the "for" contr...

    i need help with this homework web page and i need the code too Using the "do while" or the "for" control statements, have a visitor to your Web page do, or see, something repeatedly. You could have him or her enter a number of months, an interest-rate, and an amount, and print out a table with the amount on deposit. Try to make the loop appropriate to the website theme that you have picked. Use a function in your...

  • I am writing a program in c programming and it is supposed to do the following using mc9s12dg256.h microcontroller When...

    I am writing a program in c programming and it is supposed to do the following using mc9s12dg256.h microcontroller When both DIP switches #8 and #1 are high, turn on all LEDS. When both DIP switches #8 and #1 are low, turn off all LEDs When DIP switch #8 is high and #1 is low, turn on all the even numbered LEDs. When DIP switch #1 is high and #8 is low, turn on all the odd numbered LEDs. Your...

  • Need some help I am not understanding this programming class at all. We are using Microsoft...

    Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...

  • I really need some help understaning how system verilog coding works in Cygwin I am a...

    I really need some help understaning how system verilog coding works in Cygwin I am a PC user, so I in order to have a linux version or an option to run commands I installed a program called Cygwin. This program currently allows me to run .cpp file and supposedly to run verilog (.v) and systemVerilog (.sv) file, but I am not able to or familiar with how to command call them from Cygwins terminal. I would also like to...

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