Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (55 loc) · 2.18 KB
/
Copy pathmain.py
File metadata and controls
65 lines (55 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#in this code wee created a python algorithm that randomize and finds the esitmated money that the 5 gamblers made from the random attempts they used to gamble and earn money
#we used json to store the cases and in if you look at GetRandomId() function its the core function that access the json file containing the original data that python calls it and randomize the odds
import random
import json
import os
from multiprocessing import Process
#fucntion to get the json data pass folder
def Getdata():
path = os.path.join(os.path.dirname(__file__), "data.json") #gets the file path for the json data
try:
with open("c:/Users/Admin/my_python_project/data.json", "r") as file:
return json.load(file)
except FileNotFoundError:
print("Could not find data.json")
return []
#Random json algorithm it access the json file and randomie it and calculate the chances and the most tries and earned
def GetRandomId():
data=Getdata()
if not data:
return
for entry in data:
entry["tries"]=random.randint(50,100)
entry["money_won"]=random.randint(10000,50000) % 360*0.2
entry["debt"]=random.randint(0,20000)
with open("c:/Users/Admin/my_python_project/data.json","w") as file:
json.dump(data,file,indent=4)
#fetchs all the cases and who earned the most
def getallCases(data):
results=Getdata()
if not results:
return
max_value=0
winner=""
#iterates through the five cases displaying the gamblers name and attempts earned money an tries and debt
for entry in data:
case_key = list(entry)[0]
name=entry[case_key]
money = entry["money_won"]
if money > max_value:
max_value=money
winner=name
print(f"The top winner is {winner} with ${max_value} won")
#while true to simulate and loop about who is the winner
def simulate():
GetRandomId()
gamblers = Getdata()
getallCases(gamblers)
if __name__ == "__main__":
processes = []
for _ in range(10000000000): # Number of parallel simulations
p = Process(target=simulate)
p.start()
processes.append(p)
for p in processes:
p.join()