Solved

Python if then statement

Posted on 2014-01-19
2
540 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
mapBully challenge 6 178
Perl Write to Specific line in a file 15 115
what is the main difference between git clone and fetch ann pull and push commands 2 116
phython 2 41
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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