Reading in an integer array, and stopping when a string is entered

Advertisements int [] arr = new int [100]; int count = 0; int val; arr[count] = 0; while(count < arr.Length && (int.TryParse(arr[count], out val))) { arr[count] = Convert.ToInt32.Console.ReadLine(); } I want the user to enter values for an array, and when they enter ‘exit’ the while loop breaks >Solution : You should read input first… Read More Reading in an integer array, and stopping when a string is entered

I want to find the index/ or position of the word that my program found to be the longest in the string

Advertisements This is my code, I am taking input from user, I want to find out the index/ or position of the longest word in the string the user is typing. I can’t seem to figure this out! Wherever I try to find help, I get indexOf() method in which you manually have to type… Read More I want to find the index/ or position of the word that my program found to be the longest in the string

How to add text inside existing lines

Advertisements So I already know how to open / read from a file line.. for example here’s what I wrote so far. a=0 file_paths = sys.argv[1:] for path in file_paths: a=1 if(a==0): while True: print(‘\nSpecify where the path of the code is’) print(‘Example /home/user/desktop/code.txt \n’) path=input(‘Input Here: ‘) if os.path.isfile(path)==True: break else: print(‘No files found.… Read More How to add text inside existing lines

TypeError: 'float' object is not subscriptable–

Advertisements I want to calculate the average value of every three lines of data in the text. The error is as follows: Traceback (most recent call last): File "/home/code/test1.py", line 7, in <module> lines = sum(lines[i:i+3])/3 TypeError: ‘float’ object is not subscriptable with open(‘/home/data/NB_accuracy_score.txt’, ‘r’) as f: lines = f.readlines() lines = [line.strip().split(‘\t’) for line… Read More TypeError: 'float' object is not subscriptable–

How to read content of txt file the values are comma separated and add it to a list?

Advertisements I have a file that contains the following content. This is a sample of the file. The fine contains up to 1000 values. ‘1022409’, ‘10856967’, ‘11665741’ I need to read the file and create this list [‘1022409’, ‘10856967’, ‘11665741’] I’m using the following code: with open(‘Pafos.txt’, ‘r’) as f: parcelIds_list = f.readlines() print (parcelIds_list[0].split(‘,’))… Read More How to read content of txt file the values are comma separated and add it to a list?

How to use __str__ function to return a string representation of a class

Advertisements I have been tasked with creating an inventory manager in python, and one of the required is to define the following function within the class: __str__ – This function returns a string representation of a class. The class refers to a file (inventory.txt) which has the following format: Country,Code,Product,Cost,Quantity my code thus far is… Read More How to use __str__ function to return a string representation of a class

Receiving an exception and code failing when trying to delete a line from a .txt file using java

Advertisements I am trying to delete a specific line from my text file using java, My code is supposed to write the file to a temp file and skip writing the username (chosen to be deleted), it is then supposed to delete the original file and rename the new temp file to match the original.… Read More Receiving an exception and code failing when trying to delete a line from a .txt file using java

How to store data from reading lines in nodejs

Advertisements Hello I have external txt file with data to my function. How can I store read line to variable const fs = require("fs"); const readline = require("readline"); const firstVariable; [it is firstLine] const secondVariable; [it is secondLine] const thirdVariable; [it is thirdLine] const fourthVariable; [it is fourthLine] const readInterface = readline.createInterface({ input: fs.createReadStream("./slo1.in"), output:… Read More How to store data from reading lines in nodejs