[Solved] Why does this code not output the winner variable?

Try: import random class player: def __init__(self, name): self.name = name self.score = random.randint(1,6) print(self.name, self.score) player_1 = player(“Richard”) player_2 = player(“Bob”) winner=”” if player_1.score > player_2.score: winner = player_1.score print(winner) elif player_2.score> player_1.score: winner = player_2.score print(winner) else: print(“Tie.”) Output: 7 solved Why does this code not output the winner variable?

[Solved] saving large streaming data in python

A little-known fact about the Python native pickle format is that you can happily concatenate them into a file. That is, simply open a file in append mode and pickle.dump() your dictionary into that file. If you want to be extra fancy, you could do something like timestamped files: def ingest_data(data_dict): filename=”%s.pickles” % date.strftime(‘%Y-%m-%d_%H’) with … Read more

[Solved] How do I convert .txt file to a list in python?

Your problem appears to be only with displaying the results. When selecting from a list, you can either select a certain index, e.g.: print movies_list[0] or a range, e.g.: print movies_list[0:3] print movies_list[3:-1] or you can print the entire list: print movies_list You can’t use commas in the square brackets for lists. solved How do … Read more

[Solved] Python Linked list minimum value

Answering this specifically would be difficult without knowing the specifics of your node implementation, and as this is almost certainly a homework problem wouldn’t be sporting anyway. What you want to do is go through each element of the list, and compare it to the Min you have. If it’s higher, then just go to … Read more

[Solved] A class inside of a class [closed]

Yes you can do that but it would be better if you make the Males and Females into different classes and just inherit from the Human class. class Human: def __init__(self, height, weight): self.height = height self.weight = weight class Male(Human): def __init__(self, name): Human.__init__(self, height, weight) # This will inherit every attribute of the … Read more

[Solved] group given list elements using certain criteria

The only thing I could think of was to iterate over all polygons, and then loop over all the other polygons to find intersections. (Which means the algorithm has a quadratic run time complexity.) Inefficient, but it gets the job done. result = [] for i, shape in enumerate(polys): intersected_shapes = [poly for poly in … Read more