Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

In Python, I need help converting a text to an integer.

Initiate Mage
Joined
Jun 21, 2022
Messages
14
Reaction score
1
Hello, I'm a Python newbie learning about string-to-int conversions. I'm dealing with an issue that I'm not sure how to solve. This is my code:
Code:
input_string = input("Enter a number: ")
result = int(input_string)
print("The converted integer is:", result)
The code appears to be easy enough, and it works in most circumstances. However, when I attempt to enter a huge number, I become confused, therefore I read this scaler about converting string Int, but I need more information. For example, when I enter 10000000000000000000, I receive the following error:
Code:
OverflowError: int too big to convert
Python, I assumed, could handle enormous numbers. What's the problem, and how can I operate with such large numbers? Any assistance would be highly appreciated!"
 
Initiate Mage
Joined
Dec 20, 2014
Messages
16
Reaction score
1
Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate. In Python 3.0+, the int type has been dropped completely.
 
Initiate Mage
Joined
Dec 12, 2018
Messages
16
Reaction score
10
Hi,


Python:
input_string = input("Enter a number: ")
result = int(input_string)
print("The converted integer is:", str(result))

just output the int as a str
 
Junior Spellweaver
Joined
Oct 27, 2008
Messages
167
Reaction score
88
Hello, I'm a Python newbie learning about string-to-int conversions. I'm dealing with an issue that I'm not sure how to solve. This is my code:
Code:
input_string = input("Enter a number: ")
result = int(input_string)
print("The converted integer is:", result)
The code appears to be easy enough, and it works in most circumstances. However, when I attempt to enter a huge number, I become confused, therefore I read this scaler about converting string Int, but I need more information. For example, when I enter 10000000000000000000, I receive the following error:
Code:
OverflowError: int too big to convert
Python, I assumed, could handle enormous numbers. What's the problem, and how can I operate with such large numbers? Any assistance would be highly appreciated!"
int conversion means int32 conversion which is 32 bit integer mas size is from -2,147,483,648 to 2,147,483,647, to use a bigger number use int64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, the error message int too big too convert means the string number is too big to convert to an int, you should add an input limit for the string.

Code:
if  input_string.isdigit():
   result  =  int(input_string)
 
Last edited:
Back
Top