dimanche 16 avril 2023

Python: Why is my randomizer not working?

I'm new to coding with Python. I'm trying to create 5 variables and assign a random number between 1 and 100 to each one and then adding them all at the end. I typed in the random.randint() command that I've seen online but it is coming back with an error. How do I fix this?

def main():
    a=random.randint(1,100)
    b=random.randint(1,100)
    c=random.randint(1,100)
    d=random.randint(1,100)
    e=random.randint(1,100)
    result=a+b+c+d+e
    print("Here is the sum of your randomly generated numbers!:\n",result)

This is the error that pops up when I try to run the module

main()
Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    main()
  File "<pyshell#26>", line 2, in main
    a=random.randint(1,100)
NameError: name 'random' is not defined



Aucun commentaire:

Enregistrer un commentaire