[Solved] Issues with a college assignment using Python

The following program should do as you asked. There are several lines that are commented out with the # character. You may uncomment those lines if you wish to see the value of the variable referenced in the call to the debug function. Please take time to study the code so that you understand how … Read more

[Solved] is a mathematical operator classed as an interger in python

You can’t just concatenate an operator to a couple of numbers and expect it to be evaluated. You could use eval to evaluate the final string. answer = eval(str(randomnumberforq) + operator[randomoperator] + str(randomnumberforq)) A better way to accomplish what you’re attempting is to use the functions found in the operator module. By assigning the functions … Read more

[Solved] Find starting and ending indices of list chunks satisfying given condition

How about using some flags to track where you are in the checking process and some variables to hold historical info? This is not super elegant code but it is fairly simple to understand I think and fairly robust for the use case you gave. My code cross = [7,5,8,0,0,0,0,2,5,8,0,0,0,0,8,7,9,3,0,0,0,3,2,1,4,5,0,0,0,7,5] foundstart = False foundend = … Read more

[Solved] How to set a pdf background color? [closed]

from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import A4 c=canvas.Canvas(“Background”,pagesize=A4) c.setFillColorRGB(1,0,0) c.rect(5,5,652,792,fill=1) c.setTitle(“Background”) c.showPage() c.save() solved How to set a pdf background color? [closed]

[Solved] Search for column values in another column and assign a value from the next column from the row found to another column

You can try creating a dictionary from columns [‘CheckStringHere’,’AssociatedValue1′] and replace values from StringToCheck column: d = dict(df[[‘CheckStringHere’,’AssociatedValue1′]].to_numpy()) df[‘FromNumber’] = df[‘StringToCheck’].replace(d) #or df[‘FromNumber’] = df[‘StringToCheck’].map(d).fillna(df[‘FromNumber’]) print(df) StringToCheck FromNumber ToNumber CheckStringHere AssociatedValue1 \ 0 10T 56 AAA_ER 1 125T 16 FGGR_DBC 2 10T 56 3 125T 16 AssociatedValue2 0 1 2 58 3 24 2 solved … Read more

[Solved] How to perform HTTP GET operation in Python? [closed]

from socket import * s = socket() s.connect((‘example.com’, 80)) s.send(‘GET / HTTP/1.1\r\n\r\n’) print s.recv(8192) ? Or: http://docs.python.org/2/library/urllib2.html import urllib2 f = urllib2.urlopen(‘http://www.python.org/’) print f.read(100) The first option might need more header items, for instance: from socket import * s = socket() s.connect((‘example.com’, 80)) s.send(‘GET / HTTP/1.1\r\nHost: example.com\r\nUser-Agent: MyScript\r\n\r\n’) print s.recv(8192) Also, the first solution which … Read more

[Solved] Convert file of bytes to ints Python [duplicate]

You might want to read Read ints from file in python It is even more straightforward from that question. I have not checked the following code but something along the spirit of fin = open(“hi.bmp”, “rb”) out = open(“values.txt”,”rw”) value = struct.unpack(‘i’, fin.read(4))[0] out.write(“%d\n” % value) # just loop over the 2 last lines out.close() … Read more

[Solved] Python max benefit [closed]

The number of possible routes through a tree is 2**rows. The number of possible routes to a given node is given by the binomial expansion. You can grow the possible routes from the head of the tree quite simply, at each node there are only two possible next moves, their indexes in the list are … Read more

[Solved] Print index number of dictionary?

I think you have mixed up index numbers with keys. Dictionaries are formed like such: {key: value} data.keys() will return a list of keys. In your case: data.keys() [0,1,2] From there, you can call the first item, which is 0 (First item in a list is 0, and then progresses by one). data.keys()[0] 0 If … Read more

[Solved] reading files in python using minimum lines of code

print(“\n”.join([i if i != p.sub(“”, i) else “%fix_me%” for i in open(“tt.txt”).readlines()]).replace(“%fix_me%\n”, “”) Updated to reflect comments on comprehension mistake..: print(“\n”.join([i for i in open(“tt.txt”).readlines() if i != p.sub(“”, i)])) 2 solved reading files in python using minimum lines of code