[Tutor] Data chart
Good morning Sir. Excuse me to bother you but i was wondering if you can help me, please Sir. I am looking for a script (in python or fortran...) which can turn the data from Iter.dat, that i joined for you, into a chart like this: canofica lnvdmsd 10_2 ... ... 9_1 ... ... I hope i do not exagerate, and i will be very grateful to you if you can help me, for any script in python or fortran. Thank in advance. Best regards. Iter.dat Description: Netscape Proxy Auto Config ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Input Files
How do I know write the loop code for the table for both inputfiles, Table1.txt and Table2.txt and make a third table from the elements multiplied in table1.txt and table2.txt. I'm trying to Check the size of the two tables to make sure they both have the same number of rows and columns o If the tables are not the same size print an error message Once you have read the data from each file create a third table The elements in the third table are the result of multiplying each element in the first table by the corresponding element in the second table: thirdTable [i] [j] = firstTable[i] [j] * secondTable[i] [j Here is my code so far: def main(): print("Table One") (row1, column1, table1) = readInput("Table 1.txt") print("Table Two") (row2, column2, table2) = readInput("Table 2.txt") return() def readInput(filename): table = [] inputFile = open(filename, "r") # Read the first line containing the number of rows and columns line = inputFile.readline() # split the line into two strings (row, column) = line.split() # convert the strings into integers row = int(row) column = int(column) # loop on the file container, reading each line for line in inputFile : line = line.rstrip() #strip off the newline dataList = line.split() # split the string into a list table.append(dataList) # Loop through the table and convert each element to an integer for i in range(row): for j in range (column): table[i] [j] = int(table[i] [j]) # convert the string to an integer print(" %3d" % (table[i] [j]), end = " ") print() inputFile.close() # close the file return(row, column, table) # return the number of rows and columns main() Sent from Windows Mail___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Data chart
Mamy Rivo DIANZINGA wrote: > Good morning Sir. Excuse me to bother you but i was wondering if you can > help me, please Sir. > I am looking for a script (in python or fortran...) which can turn the > data from Iter.dat, that i joined for you, $ cat Iter.dat 10_2/canofica.out: No iterations CP: 14 10_2/lnvd.out: No iterations LNVD:4 10_2/msd.out: No iterations MSD:37 9_1/canofica.out: No iterations CP: 16 9_1/lnvd.out: No iterations LNVD:6 9_1/msd.out: No iterations MSD:56 > into a chart like this: > >canofica lnvdmsd > 10_2 ... ... > 9_1 ... ... > > > I hope i do not exagerate, and i will be very grateful to you if you can > help me, for any script in python or fortran. Thank in advance. > Best regards. I'm sorry, this is not a coding service; but we can help you with the problems that you as a newbie run into when you write code. Do you know Python? Do you know how to open and read a file in Python, how to split a string? This would be the minimum you should know already. If you don't, step back and find one of the many tutorials on the web and work through it. We are ready to help you over the hurdles as they arise. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Input Files
niyanax...@gmail.com wrote: > How do I know write the loop code for the table for both inputfiles, > Table1.txt and Table2.txt and make a third table from the elements > multiplied in table1.txt and table2.txt. I'm trying to Check the size of > the two tables to make sure they both have the same number of rows and > columns o If the tables are not the same size print an error message > Once you have read the data from each file create a third table The > elements in the third table are the result of multiplying each element in > the first table by the corresponding element in the second table: > thirdTable [i] [j] = firstTable[i] [j] * secondTable[i] [j > > > Here is my code so far: > def main(): [snip] Did you write this code yourself? I'm asking because > for i in range(row): > for j in range (column): > table[i] [j] = int(table[i] [j]) # convert the string to > an integer print(" %3d" % (table[i] [j]), end = " ") the snippet above already loops over a single table. Assuming you have three tables called table1, table2, and table3 you can replace the > table[i] [j] = int(table[i] [j]) part with table3[i][j] = table2[i][j] * table3[i][j] As you see all values in table3 are overwritten and thus don't matter. Therefore you can cheat and instead of building it from scratch with two for-loops just read "Table 2.txt" a second time. >def main(): >print("Table One") >(row1, column1, table1) = readInput("Table 1.txt") >print("Table Two") >(row2, column2, table2) = readInput("Table 2.txt") # add code to compare row1 with row2 and column1 with column2 here (row3, column3, table3) = readInput("Table 2.txt") # sic! # add the table multiplication code here This is not idiomatic Python, but once you have the script working in that basic form we can show you how to improve it with some of the cool features Python has to offer. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fw: Traceback
>> Exercise 1: >> def distance(x1, y1, x2, y2): >> dx = x2 - x1 >> dy = y2 - y1 >> dsquared = dx**2 + dy**2 >> result = math.sqrt(dsquared) >> print(result) >> return result > > > That's not exercise 1. Try again. > > >Exercise 1 >Write a compare function that returns 1 if x > y, 0 if x == y, and > -1 if x < y. > > > I have to get back to work so hopefully others on the mailing list can > help you. Please continue to reply to the list. Following up. I don't think I've heard back about this. Did you get help from someone else? Has the problem here been resolved? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Fw: Traceback
-- Forwarded message -- From: niyana morgan Date: Wed, Nov 19, 2014 at 5:43 PM Subject: Re: [Tutor] Fw: Traceback To: Danny Yoo No I am still stuck on what to do and this is a major project for my class. On Nov 19, 2014 6:21 PM, "Danny Yoo" wrote: > > >> Exercise 1: > >> def distance(x1, y1, x2, y2): > >> dx = x2 - x1 > >> dy = y2 - y1 > >> dsquared = dx**2 + dy**2 > >> result = math.sqrt(dsquared) > >> print(result) > >> return result > > > > > > That's not exercise 1. Try again. > > > > > >Exercise 1 > >Write a compare function that returns 1 if x > y, 0 if x == y, and > > -1 if x < y. > > > > > > I have to get back to work so hopefully others on the mailing list can > > help you. Please continue to reply to the list. > > > > Following up. I don't think I've heard back about this. Did you get > help from someone else? Has the problem here been resolved? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fw: Traceback
> On Nov 19, 2014 6:21 PM, "Danny Yoo" wrote: >> >Exercise 1 >> >Write a compare function that returns 1 if x > y, 0 if x == y, and >> > -1 if x < y. >> > >> > >> > I have to get back to work so hopefully others on the mailing list can >> > help you. Please continue to reply to the list. >> >> Following up. I don't think I've heard back about this. Did you get >> help from someone else? Has the problem here been resolved? > > No I am still stuck on what to do and this is a major project for my class. Ok. From the conversation on this thread, I think that you are confused on the following subject: on how to write functions that return useful values. I think that you are getting too fixated on being busy on your project, to the detriment of actually making progress. I don't think you've learned some basic skills that are necessary to do your project work yet. In particular, although I think you've been exposed to functions that consume inputs, I do not think you know how to write functions that return results. I am basing this judgement based on the questions you've been asking so far, and based on how you responded to my last few messages. It seemed like you were trying very hard to avoid attempting to answer my request to write a function for Exercise 1, and you seem to be jumping from problem to problem without actually finishing one. Do you agree with this assessment, or is there something I've missed? If my evaluation is correct, then I strongly suggest you ask your instructor for supplementary help. You can also feel free to ask folks on the mailing list on how to learn and practice write functions that consume and produce useful values. We'll be happy to help. I mean it! If I have misread the situation, I apologize for the presumption. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor