I wrote the code to make sure that 0.1 plus 10 times doesn't get 1, but it doesn't work.

Asked 1 years ago, Updated 1 years ago, 209 views

a=0
for i in range(10):
a+=0.1
a

I wrote the code to make sure that 0.1 is added 10 times but it doesn't work.
What's wrong?

Edit
I'm sorry I didn't know the function of editing.
I don't know what to write even if it's called a running environment, but I use Jupiter Notebook from anaconda software.
When I deleted the previous one and started over from the beginning, it was displayed as follows.
Is there something wrong with a?

File "C:\Users\user\AppData\Local\Temp\ipykernel_13580\1575381174.py", line 3
a+=0.1
^
IndentationError: expected an indented block

python

2023-01-15 08:01

1 Answers

As you can see by translating the error message or searching, the comment says a+=0.1 in the for loop is missing indentation.

Translation Results:

IndentationError—Indented block is required

Search Case Study:
Python "expected an indented block" Error Four Causes and Solutions
[Python] Expected an indented block error resolution

It should work by doing the following:

a=0
for i in range (10):
    a+=0.1#### Add indentation
a


2023-01-15 09:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.