Python print (25//10**2+1) Why is the answer 1? Isn't it 5?

Asked 2 years ago, Updated 2 years ago, 18 views

From Python

print(25//10**2+1)

The answer is 1

25//10**2 is

25 divided by 10 is 2 where 2 squared is

Isn't it 4?

Why is 0 coming out? ㅜ<

I am Corin who started studying Python for the first time today. It's a basic question, so I'm a bit embarrassed to ask this question I'm posting here because I don't have any other questions.

python

2022-09-20 16:29

1 Answers

This is because the ** operator has a higher priority than the // operator.

Therefore, 25//10**2+1 is the same as 25//(10**2)+1. 25 divided by 100 is zero, plus one, so the result is one.


2022-09-20 16:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.