School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,440 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,511 people online right now. Registration is fast and FREE... Join Now!




Help with Python number guessing game

 

Help with Python number guessing game, im getting a syntax error that i need some help with

Andrew.G

20 Jun, 2009 - 06:57 PM
Post #1

New D.I.C Head
*

Joined: 20 Jun, 2009
Posts: 4


My Contributions
CODE
print "Hello, what is your name?"
userName = raw_input()
print " Hi " + userName + ", I am thinking of a number between 1 and 20, can you guess what it is?"
import random
random = random.randomint(1,20)
print "take a guess"
guess = raw_input()
if (guess > random)
    print "Your guess is too high"
elif (guess < random)
    print "Your guess is too low"
elif (guess == random)
    print "Good job " + userName + ", you guessed my number"
    
print "The game is over"



would somebody please tell me what i am doing wrong,
help is much appreciated
P.S- This is written in Python

This post has been edited by Andrew.G: 21 Jun, 2009 - 05:38 AM

User is offlineProfile CardPM
+Quote Post


shadhin

RE: Help With Python Number Guessing Game

21 Jun, 2009 - 06:02 AM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 421



Thanked: 19 times
Dream Kudos: 3650
My Contributions
Take a look at the below code-
CODE

import random
print "Hello, what is your name?"
userName = raw_input()
print " Hi " + userName + ", I am thinking of a number between 1 and 20, can you guess what it is?"
random = random.randint(1,20)
guess = int(raw_input("Take a guess:"))
if guess > random:
    print "Your guess is too high"
elif guess < random:
    print "Your guess is too low"
elif guess == random:
    print "Good job " + userName + ", you guessed my number"
print "The game is over"

User is offlineProfile CardPM
+Quote Post

Andrew.G

RE: Help With Python Number Guessing Game

21 Jun, 2009 - 11:44 AM
Post #3

New D.I.C Head
*

Joined: 20 Jun, 2009
Posts: 4


My Contributions
OK thanks, I'm guessing my problems were the parenthesis and the not defining the guess as an integer?
User is offlineProfile CardPM
+Quote Post

shadhin

RE: Help With Python Number Guessing Game

21 Jun, 2009 - 04:59 PM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 421



Thanked: 19 times
Dream Kudos: 3650
My Contributions
Yes, there were error both in syntax of if statement and comparing a string with a number.
User is offlineProfile CardPM
+Quote Post

Andrew.G

RE: Help With Python Number Guessing Game

21 Jun, 2009 - 05:40 PM
Post #5

New D.I.C Head
*

Joined: 20 Jun, 2009
Posts: 4


My Contributions
im getting a syntax error that highlights the "gues" part of guess in the "your guess is too high string", i think something is messed up with python
User is offlineProfile CardPM
+Quote Post

shadhin

RE: Help With Python Number Guessing Game

21 Jun, 2009 - 06:50 PM
Post #6

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 421



Thanked: 19 times
Dream Kudos: 3650
My Contributions
This code run successfully-
CODE

import random
print "Hello, what is your name?"
userName = raw_input()
print " Hi " + userName + ", I am thinking of a number between 1 and 20, can you guess what it is?"
random = random.randint(1,20)
guess = int(raw_input("Take a guess:"))
if guess > random:
    print "Your guess is too high"
elif guess < random:
    print "Your guess is too low"
elif guess == random:
    print "Good job " + userName + ", you guessed my number"
print "The game is over"

Check if any piece of code is changed or not. If you have modified your code, then resubmit it so i can review it.
User is offlineProfile CardPM
+Quote Post

Andrew.G

RE: Help With Python Number Guessing Game

21 Jun, 2009 - 07:33 PM
Post #7

New D.I.C Head
*

Joined: 20 Jun, 2009
Posts: 4


My Contributions
ok, i ran it again and it worked,
thanks a bunch!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:11AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month