I have got 2 files which are imported to a main file, and are ran.
When I run it I keep getting the error:
dice_sides = random_var.randomVariable()
AttributeError: 'module' object has no attribute 'randomVariable'
>>>
My code: Main file:
import random, random_var, dice_roll
dice = [4, 6, 12]
def main():
dice_sides = random_var.randomVariable()
dice_roll.diceRoll(dice_sides)
main()
Random_var file:
import random, task_one # import modules and file to be used in program
dice = [4, 6, 12] # declare list
def randomVariable(): # function
try: # tries this expression
dice_sides = int(input("Please enter the amount of sides you want the dice that is being thrown to have. The sides available are: 4, 6 and 12: "))
except ValueError: # if user entered anything other than an integer
print("You did not enter an integer. Program restarting.")
task_one.main() # restarts, by getting the main function from "task_one" file
return dice_sides; # returns variable so it can be used in other functions
Dice_roll file:
import random, task_one
dice = [4, 6, 12]
def diceRoll(dice_sides):
if dice_sides in dice:
diceThrown = random.randrange(1, dice_sides)
print(dice_sides, " sided dice, score ", diceThrown)
else:
print("Number is invalid. Please choose either 4, 6 or 12. ")
task_one.main()
What is wrong?
ImportError: No module named random_varI even have that file saved inside the same directory as my main file.