mardi 18 juillet 2017

storing a randomly generated number in python which can be called at any time

I am trying to create a basic text adventure game in Python 3.6 in order to learn the language, but I have gotten completely stuck on a problem.

What I want to do is have Python generate a number between 1 and 6, then add 6 to that number which I have got it to do and provide me with a result, however what I can't seem to figure out is how to make that value callable so it can go up and down during the game, here is what I have so far:

import random
import time
Name = input("Before we get started lets get your character created, tell me 
what is your name?") 
print()
print ("Welcome ",Name," to the adventure of a lifetime. The next thing you 
will need to do is sort out your character stats. This will require dice 
rolls which we will do within the game.")
print()

def skillroll():
    skillroll=""
while skillroll !="Y" and skillroll != "N":
    skillroll = input("First we need to roll for your skill, would you like 
me to roll? Y/N")

if skillroll=="Y":
    print("Rolling the dice..")
    skill=random.randint(1,6)
    time.sleep(2)
    print("I rolled a", skill, " I will now add 6 to this so your skill is", 
    skill+6)
    skill=skill+6
    print()
return skillroll


skillroll()

There is more such as stamina, luck etc but If I can just find out how to work this one I can work the rest. I just cant see how to get that final answer out so I can use it during the game-play.

A friend of mine sent me this to help http://ift.tt/2tdjWTz

But I just cant see how this relates and every answer I found on Stackoverflow is for different languages.




Aucun commentaire:

Enregistrer un commentaire