davalend Posted January 13, 2006 Report Share Posted January 13, 2006 Quote Link to post Share on other sites
davalend Posted January 13, 2006 Author Report Share Posted January 13, 2006 (edited) i need some help with some c++ coding.i need to convert c++ coding to python. anyone can help me? Edited January 13, 2006 by davalend Quote Link to post Share on other sites
Hai-Etlik Posted January 13, 2006 Report Share Posted January 13, 2006 Give us some specific questions and sure, we'll help. And in case this occurs to you to try it, a listing of your C++ code with "How do I convert this to Python?" is NOT a specific question. Quote Link to post Share on other sites
davalend Posted January 14, 2006 Author Report Share Posted January 14, 2006 (edited) this is my python code----------------------------------read = open('sample.txt', 'r')a = read.readlines() for line in a : print line,------------------------------------the above code will print all the line in the file. but if i wan it to print only certain % of the line(for example: 50% of the line). how do i code it? Edited January 14, 2006 by davalend Quote Link to post Share on other sites
jcl Posted January 14, 2006 Report Share Posted January 14, 2006 (edited) The syntax foo[m:n] will give you a slice of the list foo from indices m (inclusive) to n (exclusive). len(foo) will give you the length of the list foo. Sooo...for e in foo[0:len(foo)/2]: print ewill print the first half the list. Careful if len(foo) is odd: integer division rounds down. Same trick works with strings. Edited January 14, 2006 by jcl Quote Link to post Share on other sites
davalend Posted January 14, 2006 Author Report Share Posted January 14, 2006 (edited) tks Edited January 14, 2006 by davalend Quote Link to post Share on other sites
davalend Posted January 14, 2006 Author Report Share Posted January 14, 2006 now i got other problem.t = len(a) * 0.6t will definitly be a decimal. how can i change it to the whole number without the decimal, so that i can apply to n in foo[m:n].n has to be integer Quote Link to post Share on other sites
shanenin Posted January 14, 2006 Report Share Posted January 14, 2006 is this what you are looking for?t = int(len(a) * 0.6) Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.