Python question: I need help storing the value printed/created from (randomizer.py), store it as a variable in (roulette
Posted: Sun May 15, 2022 1:45 pm
Python question:
I need help storing the value printed/created from
(randomizer.py), store it as a variable in
(roulette.py) and use it to print out the
corresponding print statement in
(roulette.py).
Ex: if randomizer.py prints out the value
1 I need roulette.py to
print You bet on the number 1. Congrats you
won!
Screenshots:
Source code:
randomizer.py
import time
import math
class PseudoRandom:
def __init__(self):
self.seed = -1
self.prev = 0
self.a = 25214903917
self.c = 11
self.m = 2**31
def get_seed(self):
seed = time.monotonic()
self.seed = int(str(seed)[-3:]) # taking the 3 decimal places at
the end of what is returned by time.monotonic()
def generate_random(self, prev_random, range):
"""
Returns a pseudorandom number between 1 and range.
"""
# if first value, then get the seed to determine starting
point
if self.seed == -1:
self.get_seed()
self.prev = raw_num = (self.a * self.seed + self.c) % self.m
# use previous value to determine next number
else:
self.prev = raw_num = (self.a * prev_random + self.c) %
self.m
return math.ceil((raw_num / self.m) * range)
if __name__ == "__main__":
test = PseudoRandom()
for i in range(1):
rand = test.generate_random(test.prev, 38)
print(rand)
roulette.py
import randomizer
# __name__ = "__main__"
# if __name__ == "__main__":
# bar()
new_rand = randomizer.rand()
# color choose and roulette simulation
def simulate():
print("Choose a number between 0-36, Red, or Black:")
answer = input(new_rand)
if answer == "0":
print("You bet on the number 0. Congrats you won!")
elif answer == "1":
print("You bet on the number 1. Congrats you won!")
#continue with the other results in roulette 2-36
elif answer == "37":
print("You bet on Red. Congrats you won!")
elif answer == "38":
print("You bet on Black. Congrats you won!")
else:
print("You lost!")
EXPLORER DI V COMP310-TEAMF-P4 > _pycache_ randomizer.py M roulette.py M 3 Los [ F. д roulette.py M randomizer.py M X randomizer.py > - 1 import time 2 import math 3 4 class PseudoRandon: 5 6 def _init__(self): 7 self.seed = -1 B selt.prev = @ 9 9 self.a = 25214903917 10 self.c = 11 11 self.m = 2 +31 12 13 def get_seed (self): 14 seed = tine.monotonic) 15 self.seed = int(str(seed) (-3:]) # taking the 3 decimal places at the end of what is returned by time. monotonico) = 16 17 def generate_randomiself, prev_randon, range): 16 19 Returns a pseudorandom number between 1 and range. 20 21 # if first value, then get the seed to determine starting point 22 if self.seed = -1: 23 self.get_seed() 24 self.prev = raw_num = (self.a self.seed + self.c) self.m 25 # use previous value to determine next number 26 else: 27 self.prev = raw_num= (self.a * prev_randon + self.c) % self.m 2B 29 return math.ceil((raw_nun / self.m) * range) 30 31 if _name__ == "_main_": 32 test = PseudoRandom) 33 for i in range(1): 34 rand = test.generate_random(test.prev, 38) 35 printrand) $03 > OUTLINE > TIMELINE main* @0AO & Ln 95, Col 20 Spaces: 4 UTF-ALF Python 3.10.2 64-bit 35: 0
EXPLORER Den O V COMP310-TEAMF-P4 - > _pycache_ randomizer.py M м roulette.py M M 09 AL д e roulette.py MX e randomizer.py M 2 roulette.py > simulate 1 import randomizer 2 3 * _name__ = "_main__" 4 if _name__ = "__main_": " 5 bar() 6 7 new_rand = randomizer, rand() B 9 #color choose and roulette simulation 19 def simulate(): 11 12 print("Choose a number between 6-36, Red, or Black:") 13 answer = input (new_rand) 14 if answer "8": 15 print("You bet on the number 0. Congrats you won!") 16 17 elif answer == "1": 16 print("You bet on the number 1. Congrats you won!") 19 20 #continue with the other results in roulette 2–36 21 22 clif answer = "37": 23 print("You bet on Red. Congrats you won!") 24 25 elif answer == "38":|| 26 print("You bet on Black. Congrats you won!"} 27 2B else: 29 print("You lost!") 30 31 32 $03 > OUTLINE > TIMELINE main* @0AO & Ln 25, Col 25 Spaces: 4 UTF-ALF Python 3.10.2 64-bit 4 A 0
I need help storing the value printed/created from
(randomizer.py), store it as a variable in
(roulette.py) and use it to print out the
corresponding print statement in
(roulette.py).
Ex: if randomizer.py prints out the value
1 I need roulette.py to
print You bet on the number 1. Congrats you
won!
Screenshots:
Source code:
randomizer.py
import time
import math
class PseudoRandom:
def __init__(self):
self.seed = -1
self.prev = 0
self.a = 25214903917
self.c = 11
self.m = 2**31
def get_seed(self):
seed = time.monotonic()
self.seed = int(str(seed)[-3:]) # taking the 3 decimal places at
the end of what is returned by time.monotonic()
def generate_random(self, prev_random, range):
"""
Returns a pseudorandom number between 1 and range.
"""
# if first value, then get the seed to determine starting
point
if self.seed == -1:
self.get_seed()
self.prev = raw_num = (self.a * self.seed + self.c) % self.m
# use previous value to determine next number
else:
self.prev = raw_num = (self.a * prev_random + self.c) %
self.m
return math.ceil((raw_num / self.m) * range)
if __name__ == "__main__":
test = PseudoRandom()
for i in range(1):
rand = test.generate_random(test.prev, 38)
print(rand)
roulette.py
import randomizer
# __name__ = "__main__"
# if __name__ == "__main__":
# bar()
new_rand = randomizer.rand()
# color choose and roulette simulation
def simulate():
print("Choose a number between 0-36, Red, or Black:")
answer = input(new_rand)
if answer == "0":
print("You bet on the number 0. Congrats you won!")
elif answer == "1":
print("You bet on the number 1. Congrats you won!")
#continue with the other results in roulette 2-36
elif answer == "37":
print("You bet on Red. Congrats you won!")
elif answer == "38":
print("You bet on Black. Congrats you won!")
else:
print("You lost!")
EXPLORER DI V COMP310-TEAMF-P4 > _pycache_ randomizer.py M roulette.py M 3 Los [ F. д roulette.py M randomizer.py M X randomizer.py > - 1 import time 2 import math 3 4 class PseudoRandon: 5 6 def _init__(self): 7 self.seed = -1 B selt.prev = @ 9 9 self.a = 25214903917 10 self.c = 11 11 self.m = 2 +31 12 13 def get_seed (self): 14 seed = tine.monotonic) 15 self.seed = int(str(seed) (-3:]) # taking the 3 decimal places at the end of what is returned by time. monotonico) = 16 17 def generate_randomiself, prev_randon, range): 16 19 Returns a pseudorandom number between 1 and range. 20 21 # if first value, then get the seed to determine starting point 22 if self.seed = -1: 23 self.get_seed() 24 self.prev = raw_num = (self.a self.seed + self.c) self.m 25 # use previous value to determine next number 26 else: 27 self.prev = raw_num= (self.a * prev_randon + self.c) % self.m 2B 29 return math.ceil((raw_nun / self.m) * range) 30 31 if _name__ == "_main_": 32 test = PseudoRandom) 33 for i in range(1): 34 rand = test.generate_random(test.prev, 38) 35 printrand) $03 > OUTLINE > TIMELINE main* @0AO & Ln 95, Col 20 Spaces: 4 UTF-ALF Python 3.10.2 64-bit 35: 0
EXPLORER Den O V COMP310-TEAMF-P4 - > _pycache_ randomizer.py M м roulette.py M M 09 AL д e roulette.py MX e randomizer.py M 2 roulette.py > simulate 1 import randomizer 2 3 * _name__ = "_main__" 4 if _name__ = "__main_": " 5 bar() 6 7 new_rand = randomizer, rand() B 9 #color choose and roulette simulation 19 def simulate(): 11 12 print("Choose a number between 6-36, Red, or Black:") 13 answer = input (new_rand) 14 if answer "8": 15 print("You bet on the number 0. Congrats you won!") 16 17 elif answer == "1": 16 print("You bet on the number 1. Congrats you won!") 19 20 #continue with the other results in roulette 2–36 21 22 clif answer = "37": 23 print("You bet on Red. Congrats you won!") 24 25 elif answer == "38":|| 26 print("You bet on Black. Congrats you won!"} 27 2B else: 29 print("You lost!") 30 31 32 $03 > OUTLINE > TIMELINE main* @0AO & Ln 25, Col 25 Spaces: 4 UTF-ALF Python 3.10.2 64-bit 4 A 0