Python Forum
Read text file, process data and print specific output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read text file, process data and print specific output
#1
Please someone HELP!!!!
I have the below homework and no code I've tried worked so far!!!!!
_________________________________________________________________________________________________________
Write a Python script that will read a text file whose lines contain numbers separated by white-space; as output, the program will produce for each line of the original text file another line that will contain two numbers: the first will be the total number of entries in the line, and the second will be the sum of the numbers in the line.
Example:
Input file (test1.txt) contents:
1 3 5 12 0
2 3
1
-1 1
Expected Output:
Enter text file name: test1.txt
Output:
5 21
2 5
1 1
2 0
Reply


Messages In This Thread
Read text file, process data and print specific output - by Happythankyoumoreplease - Feb-20-2020, 12:02 AM
RE: Help!!!! Simple Code - by micseydel - Feb-20-2020, 02:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation URGENT: How to plot data from text file. Trying to recreate plots from MATLAB JamieAl 4 3,843 Dec-03-2023, 06:56 AM
Last Post: Pedroski55
  dictionary output to text file (beginner) Delg_Dankil 2 1,389 Jul-12-2023, 11:45 AM
Last Post: deanhystad
  Output File ? Kessie1971 11 2,406 May-11-2023, 08:31 AM
Last Post: buran
  Print not appearing in output dgizzly 1 1,356 Oct-14-2022, 09:55 PM
Last Post: rob101
  Using regex to count specific character in file shamishd 1 1,725 Oct-01-2021, 07:33 AM
Last Post: snippsat
  Reading a text until matched string and print it as a single line cananb 1 2,122 Nov-29-2020, 01:38 PM
Last Post: DPaul
  computer science coursework, read the text please and tell me if theres any specifics sixcray 4 2,822 Nov-11-2020, 03:17 PM
Last Post: buran
  Can we store value in file if we open file in read mode? prasanthbab1234 3 2,737 Sep-26-2020, 12:10 PM
Last Post: ibreeden
  Working with text data APK 4 2,655 Aug-22-2020, 04:48 AM
Last Post: buran
  [split] how to read a specific row in CSV file ? laxmipython 2 9,104 May-22-2020, 12:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020