Project 9 indentation error



I am getting this errors i have used tabs properly too not any spaces.

Tabs are replaced from left to right by 1to8 spaces such that the total number of characters up to and including the replacement is a multiple of eight

Python Tab Error:occurs when inconsistent use of tabs and spaces in indentation , error is raised when you try to indent code using both spaces and tabs

You fix this error by sticking to either spaces or tabs in a program and replacing any tabs or spaces that do not use your preferred method of indentation.
That means we need not to leave so much space , for the image you have attached after try: you just press enter and after that a space bar , only that much indentation is required.

Tabs should be used to remain consistent with code that is already indented with tabs .
Python 3 doesn’t allow mixing the use of tabs and spaces for indentation.

hope this might help you :))

I will give you a solution to this instead of complicating it even more, lmao.

After try: the next line starts after some space. That is added indentation.

To solve it:

  1. CUT the whole code below try:
  2. Move your cursor at the end of try: and then hit enter.
    (In the next line, you’ll be moved little bit ahead below the line of try: THAT IS THE INDENTATION.)
  3. Paste the code that you copied and make sure no more extra spaces were added.

Please tell here if it worked. And if it didn’t I will give you another solution.

@akshayan.sinha i press enter after try but it reaches to starting of line ie in very start and my ques is that in our demo code also after try there is some space so i put tab after it accordingly

1 Like

In that case, I suggest you to use a GUI based linux. There, you can make python files on text editors. Easier to manipulate tabs, spaces, indentations etc.

GUI based linux are available for Ubuntu also, it looks similar like windows, like opening applications.

There, use terminal to run the program, and text editors to write them.

Ubuntu latest - https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso?_ga=2.235890369.1366413299.1622384331-1701926123.1621861186

Using tabs manually wont help

ooh but its 2.7GB…r u sure about it? and one thing is that how to copy and paste in ubuntu via virtual box?

In that case, use Debian OS. Its available for 337MB.

Link - https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.9.0-amd64-netinst.iso

It is slow and slaggy, but does the work. Remember to tick mark the Desktop Environment while installing to use the feature i talked about.

actually i have solved indentation error but its one syntax error here


can u help me in this?

Your if statement is not under the error handling try condition.

Must be under that for the code to work.

Same as the tabs and spaces problem. Shift the whole If condition one step to the right.

@harshitakha925thank u!

1 Like

@swastishree10 I think your code is running now

also as per your last image, your if statement should be under try condition ,
And your try , except , time , should be at same indentation.

just let me know if any other problem :))

@harshitakha925 indentation issue is not there now its showing a syntax error.

@swastishree10 in the above shared code the if block is at the same indentation level as that of try block. But it should be a level inner (deep) than the try block. The try and except block should be at the same identation level.

As you must have know after going through the training content that the LM35 sensor value is divided by 10.24 to get the correct temperature value. So I am sharing my customized code, hope it will clear your doubts.


Hope it solves your problem :slight_smile:

1 Like

yes there is a error because you if statement is same indented as (try,except,time)
to correct it press a spacebar before if
this will help

you can also see a arrow on if when its showing error… the arrow is because of that only

@swastishree10

also have attached ss for refrence :))

1 Like

@harshitakha925 See the print function is at the correct indentation level. Now see that if block is a space behind the correct indentation that is why the error is coming.

At last the sleep function should be executed at the end of while loop ( so it should be a level deeper than the while loop ) but you have assigned wrong indentation to that also.

@swastishree10 I have pasted the correct indented code above. Go through that and I hope you will fund it useful

1 Like

@vishalvats2000 you are correct about the if indentation

sleep function is under while loop, as will put the program to sleep once every loop iteration. so it is indented deeper than while loop.
the (try, except, time) all three should be indented at same level ,
so my ss is error free, and well executed :))

try:
(gap)if sensor_value…

this gap tells that if is under the try condition. And is called indented under try.

SO, in your program, if statement is in the very beginning of the line, without any gap. That is why the whole if condition is not running.

This indentation will be visible to you in an IDE.
Use the desktop environment version of ubuntu, to be free of this chaos.

i did it still the same error in if statement syntax error is showing.
also i want to know how your tabs are working perfectly and how to copy and paste here?