Reputation: 151
I've tried for ages on how to get this to work. It is supposed to choose a random number with 'from random import randrange' followed by the line 'x = randrange(1,3). I have used that generator at other times and it worked then but it will not work with this :/. Here is the code:
from random import randrange
numberboy == randrange(7,9)
if numberboy == "7":
print ("You unluckily fall into a pit!")
health -= 1
if health == "1":
print ("You drop to your knees and lie, filled with pain in the pit. You drop to the floor. Your quest is over.")
print ("Your health has fallen to " + str(health) + ". ")
if numberboy == "8" or "9":
print ("You could have fallen into a pit but you luckily didn't!")
print ("You find a path leading of to another room.")
print ("You walk down the path and find a light illuminating an elvish sword!")
print ("You walk out of an escape path and find youself coming out of a secret entrance at the clearing.")
import time
Btw, earlier on a use 'numberboy = 0' in order for it to work (numberboy is the variable, x)
Upvotes: 0
Views: 1941
Reputation: 314
So a few notes: please see my comments in the code. you need to declare health, you have numberboy evaluating not equating. those two things are the biggest problems in your code. my advice is to download pycharm and learn how to debug your code better. With more experience these mistakes would not have been made.
from random import randrange
import time #this is unused
numberboy = randrange(7,9) # you had this evaluating not declared
print numberboy
health = 10 #you did not declare health
if numberboy == 7: # numberboy is a int type no need for making it a string
print ("You unluckily fall into a pit!")
health -= 1
if health == 1:
print ("You drop to your knees and lie, filled with pain in the pit. You drop to the floor. Your quest is over.")
print ("Your health has fallen to " + str(health) + ". ")
if numberboy == 8 or 9:
print ("You could have fallen into a pit but you luckily didn't!")
print ("You find a path leading of to another room.")
print ("You walk down the path and find a light illuminating an elvish sword!")
print ("You walk out of an escape path and find youself coming out of a secret entrance at the clearing.")
Upvotes: 0
Reputation: 1
You need to use random.randint(floor,ceil) for integers, and random.random(floor,ceil) for decimals
Upvotes: 0
Reputation: 311
numberboy == randrange(7,9)
is your problem. Just replace it by
numberboy = randrange(7,9)
and randrange(x,y)
will give you this kind of number x <= nb < y
so it can't be y
Upvotes: 0
Reputation: 1199
Couple of things I noticed:
numberboy == randrange(7,9)
should be numberboy = randrange(7,9)
NameError
numerboy == 7
instead of numberboy == '7'
Upvotes: 0
Reputation: 1638
You are comparing a number to a string...
Use:
if numberboy == 7:
instead of:
if numberboy == "7":
The same with health, use this comparison:
if health == 1:
Also, this is wrong:
if numberboy == "8" or "9":
Use this instead:
if numberboy == 8 or numberboy == 9:
Hope this helps
Upvotes: 3