Solved

Python if then statement

Posted on 2014-01-19
2
535 Views
Last Modified: 2014-01-19
In my Python code I wrote like the following:
v = 0
v_before = 0

class MainPage(webapp2.RequestHandler):

stats = memcache.get_stats()
global v
v = stats['hits']
if v == v_before:
self.response.out.write('<b>Yes!</b>')
else:
self.response.out.write('<b>No!</b>')

I get the error:
  File "/Users/main2.py", line 37
    if v == v_before:
                    ^
IndentationError: unindent does not match any outer indentation level

Could you let me know how I could do the conditional print as above?
0
Comment
Question by:toooki
2 Comments
 
LVL 3

Accepted Solution

by:
Conner Turner earned 500 total points
ID: 39793038
Hello,

As Python relies heavily on indentation you should be aware that an if statement requires a Tab or 4 spaces between the deceleration and the execution method:

I have re-written your code to follow the indentation rules:

v = 0
v_before = 0

class MainPage(webapp2.RequestHandler):
    stats = memcache.get_stats()
    global v
    v = stats['hits']
    if v == v_before:
        self.response.out.write('<b>Yes!</b>')
    else:
        self.response.out.write('<b>No!</b>')

Open in new window


HTH,
Conner
0
 

Author Comment

by:toooki
ID: 39793157
Thank you! It works.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 70
how to check case insensitive substring 5 60
splitOdd10 challenge 5 104
base64 decode encode 12 133
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question