I am working on a program that generates random asteroid statistics. I want it to generate a random name, type, and surface gravity.
Examples:
MUS-983 A Type Surface Gravity: 0.31 m/s²
The code I have so far is: import string, random def pick(num): for j in range(num): print("".join([random.choice(string.ascii_uppercase) for i in range(3)])+"-"+"".join([random.choice(string.digits) for i in range(3)])+" "+"".join([random.choice(['A Type','B Type','C Type'])])+"Surface Gravity: "+"".join([random.randint(0.01, 0.39)]))
Which has worked well until i put in the part about Surface gravity on the end. Now I have a few questions. First is when I run the program i get a error:
Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> pick(1) File "/Users/James/Desktop/Asteroid Name Generator.py", line 4, in pick print("".join([random.choice(string.ascii_uppercase) for i in range(3)])+"-"+"".join([random.choice(string.digits) for i in range(3)])+" "+"".join([random.choice(['A Type','B Type','C Type'])])+" "+"".join([random.randint(0.01, 0.39)])) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/random.py", line 218, in randint return self.randrange(a, b+1) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/random.py", line 182, in randrange raise ValueError("non-integer arg 1 for randrange()") ValueError: non-integer arg 1 for randrange()
The second question is how to integrate the 'm/s²' title in front of the randomly generated surface gravity decimal.
Thank you!
Aucun commentaire:
Enregistrer un commentaire