Diference from python2 to python3 in this code to solve it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Diference from python2 to python3 in this code to solve it

How do I have to fix the line 11, I write this code in python 2.7, and ends well, but in python3 always give me an error, it seems that is in line 11, because the result of division n/2 always is a float, and n have to be an int number for range, thanks https://code.sololearn.com/cQI41S4ruQ66/?ref=app

9th Jul 2020, 4:15 AM
TiTo90
TiTo90 - avatar
5 Answers
+ 8
The range function only accepts integer values as its parameters. Use the floor division operator instead : n//2+1 This will remove the above error.
9th Jul 2020, 4:24 AM
Nova
Nova - avatar
+ 6
TiTo90 Yeah, SoloLearn and many other Online Courses don't provide in-depth knowledge. You need to refer multiple resources to learn. Here's a thread that contains a few Python 3 resources: https://www.sololearn.com/Discuss/821134/?ref=app Hope it's helpful 🙂
9th Jul 2020, 11:28 AM
Nova
Nova - avatar
+ 5
No, need for python 2 now... It's no more used. https://code.sololearn.com/cIb0jKxWo4Oq/?ref=app
9th Jul 2020, 4:34 AM
Arctic Fox
Arctic Fox - avatar
+ 1
By the way, for finding the divisors of a number, as when we check for primality, it's enough to search up to the square root of n, not up to the half of n
9th Jul 2020, 4:31 AM
Bilbo Baggins
Bilbo Baggins - avatar
0
The thing is that I'm studying by a book that teach 2.7, and this is the best book I have, it have exercises and everything well explain, I've searching in other courses in internet, and even here in solo learn, and they teach very superficial 😁😁😁, and since python 2 to 3 at least now by this book, there are so much, I continue studying 🤷🤷🤷
9th Jul 2020, 4:46 AM
TiTo90
TiTo90 - avatar