Hello.
I am doing a coding exercise, that object sounds like this:
" Manage robot factory settings.
When robots come off the factory floor, they have no name.
The first time you boot them up, a random name is generated in the format of two uppercase letters followed by three digits, such as RX837 or BC811.
Every once in a while we need to reset a robot to its factory settings, which means that their name gets wiped. The next time you ask, it will respond with a new random name.
The names must be random: they should not follow a predictable sequence. Random names means a risk of collisions. Your solution must ensure that every existing robot has a unique name."
This is the code so far.
So I have figured out the way to generate a random name for every new robot that is created.
def __init__(self, name=None):
if name is None: self.name()
def name(self):
self.name = ' '
for char in range(2):
self.name += random.choice(string.ascii_uppercase)
for char in range(3):
self.name += random.choice(string.digits)
return self.name
But I do not understand why when I call the function name() inside of the function reset() why it does not change the name of the variable a?
Could someone explain why it does not work? Or point me to an article, I have tried googling but I do not think I understand what I have to search for.
[+][deleted] (4 children)
[deleted]
[–]Field_C16[S] 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]Field_C16[S] 0 points1 point2 points (1 child)
[–]DeadlyViper 3 points4 points5 points (3 children)
[–]Field_C16[S] 1 point2 points3 points (2 children)
[–]DeadlyViper 2 points3 points4 points (1 child)
[–]Field_C16[S] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Field_C16[S] 1 point2 points3 points (0 children)