Solved

Python if then statement

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countClumps  challenge 10 105
Is there a way to create a custom installer for Python 3.5? 5 63
How does this Python sort work? 5 61
rhino JavaScript import, load 25 66
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

929 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

11 Experts available now in Live!

Get 1:1 Help Now