Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81056 > unrolled thread

Beginner

Started byKarthik Reddy <challakarthik@gmail.com>
First post2014-11-19 22:40 -0800
Last post2014-11-20 23:11 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Beginner Karthik Reddy <challakarthik@gmail.com> - 2014-11-19 22:40 -0800
    Re: Beginner Steven D'Aprano <steve@pearwood.info> - 2014-11-20 06:47 +0000
    Re: Beginner Karthik Reddy <challakarthik@gmail.com> - 2014-11-20 23:11 -0800

#81056 — Beginner

FromKarthik Reddy <challakarthik@gmail.com>
Date2014-11-19 22:40 -0800
SubjectBeginner
Message-ID<5811dc65-d05a-4e29-96de-eb1e4fd8aa4d@googlegroups.com>
Hi all 

I am python beginner I am trying the below code and getting incorrect syntax in python (3.3.2)

number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print ("Congratulations, you guessed it.")
running = False # this causes the while loop to stop
elif guess < number:
print ("No, it is a little higher than that.")
else:
print ("No, it is a little lower than that.")
else:
print ("The while loop is over.")
# Do anything else you want to do here
print ("Done")

Please help me with this 

Thank you in advance

[toc] | [next] | [standalone]


#81057

FromSteven D'Aprano <steve@pearwood.info>
Date2014-11-20 06:47 +0000
Message-ID<546d8e70$0$12899$c3e8da3$5496439d@news.astraweb.com>
In reply to#81056
On Wed, 19 Nov 2014 22:40:09 -0800, Karthik Reddy wrote:

> Hi all
> 
> I am python beginner I am trying the below code and getting incorrect
> syntax in python (3.3.2)

You need to indent the while and if blocks.

Instead of writing:

while running:
code


you need to write:

while running:
    code


See the indent? You should use either 1 tab or 4 spaces, but not both.


Another problem with your code, although it is not a syntax error, is 
that you have:

guess = int(raw_input('Enter an integer : '))


That is from Python 2. In Python 3, use:

guess = int(input('Enter an integer : '))

(don't forget to indent it correctly).

There may be other problems, please fix these first and if you have any 
other problems copy and paste the FULL error, everything from the line 
starting

Traceback 

to the end of the error message.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#81176

FromKarthik Reddy <challakarthik@gmail.com>
Date2014-11-20 23:11 -0800
Message-ID<545cb0a1-c052-42f7-abe7-2a70993880ad@googlegroups.com>
In reply to#81056
Now Its working 

Thanks a lot Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web