Solved

Python if then statement

Posted on 2014-01-19
2
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
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.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

717 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