I'm learning Python and I'm practicing by creating a simple game: rock, paper, scissors. I have created two Python modules called random_number.py and ro_pa_sc.py. The first one includes the code to generate a random string and the second one implements the game itself.
This is random_number.py:
def r_p_s():
import random
random.choice([1, 2, 3])
if random.choice([1, 2, 3]):
return "r"
if random.choice([1, 2, 3]):
return "p"
if random.choice([1, 2, 3]):
return "s"
And this is ro_pa_sc.py:
#!/usr/bin/python
import random_number
def game():
random_number.r_p_s()
print r_p_s()
if __name__ == "__main__":
game()
However, when I try to run ro_pa_sc.py from the command line in Bash, I get the following error messages:
Error 1:
File "ro_pa_sc.py", in module "game()"
Error 2:
File "ro_pa_sc.py", in game print r_p_s()
I don't know what the errors could be, since I have checked I imported the modules and I made sure the syntax was correct... It seems that the random_number module might be the problem, but again, I don't know why.
Could anyone tell where my errors are?
if __name__outsidegame().