Discuss Scratch

enspcds
Scratcher
100+ posts

Help in Python?

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
Ghost Game
from random import randint
print ('Ghost Game')
feeling_brave = True
score = 0
while feeling_brave:
ghost_door = randint (1, 3)
print ('Three doors ahead…')
print ('A ghost behind one.')
print ('Which door do you open?')
door = input ('3, 2, or 1?')
door_num = int('door')
if door_num == ghost_door:
print ('GHOST!')
feeling_brave = false
else:
print ('No ghost!')
print ('You enter the next room!')
score = score + 1
print ('Game over. You scored', score)


A cute little slither.io animation!
Need something real quick? Then come to this shop!
Also, please check out my new Emoji Dictionary! It would be greatly appreciated!
But sadly, the rest of my signature has been eaten by my pet kumquat.
BlueCrayfish
Scratcher
500+ posts

Help in Python?

Sorry, I only know Python 2, and not Python 3. Do you have an IDE with a Debugger or are you using an online compiler?

Does this pique your interest:
A 26 year old accountant was framed for changing records, who, now a fugitive, flees, and tries to find the organization who actually coordinated the scam.

Would you be interested in joining:
A collab that is checked every day and managed well.

Then why don't you click the sunglasses guy?

enspcds
Scratcher
100+ posts

Help in Python?

BlueCrayfish wrote:

Sorry, I only know Python 2, and not Python 3. Do you have an IDE with a Debugger or are you using an online compiler?
What do you mean?

A cute little slither.io animation!
Need something real quick? Then come to this shop!
Also, please check out my new Emoji Dictionary! It would be greatly appreciated!
But sadly, the rest of my signature has been eaten by my pet kumquat.
BookOwl
Scratcher
1000+ posts

Help in Python?

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
 Ghost Game 
from random import randint
print ('Ghost Game')
feeling_brave = True 
score = 0
while feeling_brave:
    ghost_door = randint (1, 3)
    print ('Three doors ahead...')
    print ('A ghost behind one.')
    print ('Which door do you open?')
    door = input ('3, 2, or 1?')
    door_num = int('door')
    if door_num == ghost_door:
        print ('GHOST!')
        feeling_brave = false
    else:
        print ('No ghost!')
        print ('You enter the next room!')
        score = score + 1
print ('Game over. You scored', score)
Here's my fixed version with comments explaining what I changed:
 
# Ghost Game # This needs to be a comment
from random import randint
print ('Ghost Game')
feeling_brave = True 
score = 0
while feeling_brave:
    ghost_door = randint (1, 3)
    print ('Three doors ahead...')
    print ('A ghost behind one.')
    print ('Which door do you open?')
    door = input ('3, 2, or 1?')
    door_num = int(door) # You need to use the door variable, NOT the string 'door'
    if door_num == ghost_door:
        print ('GHOST!')
        feeling_brave = false
    else:
        print ('No ghost!')
        print ('You enter the next room!')
        score = score + 1
print ('Game over. You scored', score)
 [\code]

who needs signatures
Savio-5002
Scratcher
45 posts

Help in Python?

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
Ghost Game
from random import randint
print ('Ghost Game')
feeling_brave = True
score = 0
while feeling_brave:
ghost_door = randint (1, 3)
print ('Three doors ahead…')
print ('A ghost behind one.')
print ('Which door do you open?')
door = input ('3, 2, or 1?')
door_num = int('door')
if door_num == ghost_door:
print ('GHOST!')
feeling_brave = false
else:
print ('No ghost!')
print ('You enter the next room!')
score = score + 1
print ('Game over. You scored', score)

Hey I read that book!
There's a space in between randint and the numbers on the
 ghost_door = randint (1,3)
^
line.
And there needs to be hashtags on the first line, or you'll get a NameError. Can you specify the error, if that did not fix it?(e.g. NameError, SyntaxError, TypeError, errno 10035)

Last edited by Savio-5002 (Aug. 27, 2016 20:16:45)


Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program. -Linus Torvalds
This awesome quote protects it from unawesome kumquats, which cannot handle it's awesomeness.
lugga
Scratcher
500+ posts

Help in Python?

BookOwl wrote:

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
-snip-
Here's my fixed version with comments explaining what I changed:
 
# Ghost Game # This needs to be a comment
from random import randint
print ('Ghost Game')
feeling_brave = True 
score = 0
while feeling_brave:
    ghost_door = randint (1, 3)
    print ('Three doors ahead...')
    print ('A ghost behind one.')
    print ('Which door do you open?')
    door = input ('3, 2, or 1?')
    while not door in ['1', '2', '3']: # Makes sure you inputted a valid number and not an arbitrary string / number
        door_num = int(door) # You need to use the door variable, NOT the string 'door'
    if door_num == ghost_door:
        print ('GHOST!')
        feeling_brave = False
    else:
        print ('No ghost!')
        print ('You enter the next room!')
        score += 1 # Saves time when writing. It is the same as "score = score + 1"
print ('Game over. You scored', score)
 

Some more changes and explanations why.
(I only made 1 change and added another line
so that's 4 changes from the original in total)

Edit: Changed wording in one of the comments

Last edited by lugga (Aug. 24, 2016 15:44:15)

lugga
Scratcher
500+ posts

Help in Python?

Savio-5002 wrote:

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
Ghost Game
from random import randint
print ('Ghost Game')
feeling_brave = True
score = 0
while feeling_brave:
ghost_door = randint (1, 3)
print ('Three doors ahead…')
print ('A ghost behind one.')
print ('Which door do you open?')
door = input ('3, 2, or 1?')
door_num = int('door')
if door_num == ghost_door:
print ('GHOST!')
feeling_brave = false
else:
print ('No ghost!')
print ('You enter the next room!')
score = score + 1
print ('Game over. You scored', score)

Hey I read that book!
There's a space in between randint and the numbers on the
 ghost_door = randint (1,3)
^
line.
And there needs to be hashtags on the first line, or you'll get a NameError. Can you specify the error, if that did not fix it?(e.g. NameError, SyntaxError, TypeError, errno 10035)


define Promote underrated OSes
Windows Vista rules (100000000000000000000000000000000000000000000000000000000000000000000)%
Windows Me rules (100) %
Windows 8 doesn't deserve any promotion
Neither does Windows 7
Or any other but<not<Windows Vista[because it rules]>>
say [YAY WINDOWS VISTA!!!!]
Hi please don't blockspam (adding unnecessary scratchblocks) if you want it as your signature you can add it there by going to the discussion home and at the bottom of the page and clicking “edit my signature”.
enspcds
Scratcher
100+ posts

Help in Python?

Savio-5002 wrote:

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
Ghost Game
from random import randint
print ('Ghost Game')
feeling_brave = True
score = 0
while feeling_brave:
ghost_door = randint (1, 3)
print ('Three doors ahead…')
print ('A ghost behind one.')
print ('Which door do you open?')
door = input ('3, 2, or 1?')
door_num = int('door')
if door_num == ghost_door:
print ('GHOST!')
feeling_brave = false
else:
print ('No ghost!')
print ('You enter the next room!')
score = score + 1
print ('Game over. You scored', score)

Hey I read that book!
There's a space in between randint and the numbers on the
 ghost_door = randint (1,3)
^
line.
And there needs to be hashtags on the first line, or you'll get a NameError. Can you specify the error, if that did not fix it?(e.g. NameError, SyntaxError, TypeError, errno 10035)


define Promote underrated OSes
Windows Vista rules (100000000000000000000000000000000000000000000000000000000000000000000)%
Windows Me rules (100) %
Windows 8 doesn't deserve any promotion
Neither does Windows 7
Or any other but<not<Windows Vista[because it rules]>>
say [YAY WINDOWS VISTA!!!!]

Savio-5002 wrote:

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
Ghost Game
from random import randint
print ('Ghost Game')
feeling_brave = True
score = 0
while feeling_brave:
ghost_door = randint (1, 3)
print ('Three doors ahead…')
print ('A ghost behind one.')
print ('Which door do you open?')
door = input ('3, 2, or 1?')
door_num = int('door')
if door_num == ghost_door:
print ('GHOST!')
feeling_brave = false
else:
print ('No ghost!')
print ('You enter the next room!')
score = score + 1
print ('Game over. You scored', score)

Hey I read that book!
There's a space in between randint and the numbers on the
 ghost_door = randint (1,3)
^
line.
And there needs to be hashtags on the first line, or you'll get a NameError. Can you specify the error, if that did not fix it?(e.g. NameError, SyntaxError, TypeError, errno 10035)


Cool! It was a syntax error, or something like that…

A cute little slither.io animation!
Need something real quick? Then come to this shop!
Also, please check out my new Emoji Dictionary! It would be greatly appreciated!
But sadly, the rest of my signature has been eaten by my pet kumquat.
Savio-5002
Scratcher
45 posts

Help in Python?

lugga wrote:

Savio-5002 wrote:

enspcds wrote:

I just started using Python, and made a simple game and checked over everything but it has an error. Can anybody help?
Ghost Game
from random import randint
print ('Ghost Game')
feeling_brave = True
score = 0
while feeling_brave:
ghost_door = randint (1, 3)
print ('Three doors ahead…')
print ('A ghost behind one.')
print ('Which door do you open?')
door = input ('3, 2, or 1?')
door_num = int('door')
if door_num == ghost_door:
print ('GHOST!')
feeling_brave = false
else:
print ('No ghost!')
print ('You enter the next room!')
score = score + 1
print ('Game over. You scored', score)

Hey I read that book!
There's a space in between randint and the numbers on the
 ghost_door = randint (1,3)
^
line.
And there needs to be hashtags on the first line, or you'll get a NameError. Can you specify the error, if that did not fix it?(e.g. NameError, SyntaxError, TypeError, errno 10035)


-removed-
Hi please don't blockspam (adding unnecessary scratchblocks) if you want it as your signature you can add it there by going to the discussion home and at the bottom of the page and clicking “edit my signature”.
I wish you told me that earlier…

Last edited by Savio-5002 (Aug. 27, 2016 20:18:04)


Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program. -Linus Torvalds
This awesome quote protects it from unawesome kumquats, which cannot handle it's awesomeness.
enspcds
Scratcher
100+ posts

Help in Python?

Thanks everyone!

A cute little slither.io animation!
Need something real quick? Then come to this shop!
Also, please check out my new Emoji Dictionary! It would be greatly appreciated!
But sadly, the rest of my signature has been eaten by my pet kumquat.

Powered by DjangoBB