Skip to content
Sign upLog in
← Back to Community

int() function broken?

Profile icon
johnj

I have an input that I turn into an integer for some math stuff, but when I put in a decimal, it comes out with an error:
ValueError: Invalid literal for int() with base 10: '1.75'

Answered by PYer [earned 5 cycles]
View Answer
Voters
Profile icon
teymour
Profile icon
johnj
Comments
hotnewtop
Profile icon
PYer

You would have to use float(). An integer is a whole number, so it cannot have a decimal point, and the int() would not work. And by the way, int() is not actually a function. It is a class, pre-defined by python.

Please upvote if this was helpful in any way!

Profile icon
johnj

Thanks for the help and the quick reply.

Profile icon
AllAwesome497

@johnj
just a minor correction to
@PYer
's comment, an int() can be negative too ;)

Profile icon
PYer

@johnj
No problem!

Profile icon
PYer
Profile icon
johnj

now python seems to think that 500 isn't less than 10000.
put in 10000 in the first input, 500 in the third, and any numbers in the other two.
the final output should be more than 1, but it's not.

my code:
a = input('linear start num: ')
b = input('linear increase num: ')
c = input('exponential start num: ')
d = input('exponential increase num: ')
num = 1
print('\n\n\n')
while c < a:
num += 1
a = float(a) + float(b)
c = float(c) * float(d)
print(num)
https://repl.it/@johnj/Fixing-the-mind-numbing-monotony-of-algebra

Please Help!

Profile icon
AllAwesome497

@johnj
If exponential increase is supposed to be the exponent (c^d) then u did (c*d)

Profile icon
johnj

@AllAwesome497
no, it's supposed to be multiplication.

Profile icon
pyelias

@johnj
10000 is less than 500 alphabetically, which is how they're being compared before you convert them to floats.

Profile icon
johnj

thanks