Solved

Python if then statement

Posted on 2014-01-19
2
527 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now