← Back to Community
##### I'm desperate
Profile icon
FARHEENPALAGIRI

Hey guys. Wassup?? Well, I was trying to write this code for like two days now and I am just extremely stuck. Like can someone please help me?? I am so confused.

So for this code, I have to get input and insert it into the equation a = bx. That part is simple. Then if the answer is an integer, I have to print the integer, and I need to print either no solutions or many solutions. So far, I've written this as my answer:

a = int(input())
b = int(input())

x = b/a

if a == b:
print("many solutions")

elif x % 1 == 0:
y = eval('x')
print(y)

else:
print("no solution")

For starters, the system wants my answer in the form of -2. But the code keeps outputting -2.0. How do I make it stop doing that? And can you guys look at the 'no solution' and 'many solutions' part of the answer? I'm pretty sure that's off. Also can someone tell me if I'm using the eval statement right? I just got introduced to that pretty recently and am not sure if it's correct. Thank you!!

Answered by mat1 [earned 5 cycles]
Voters
Profile icon
FARHEENPALAGIRI
hotnewtop
Profile icon
mat1

Never ever ever ever use eval(). Use int() to automatically convert it to an integer instead

Please upvote my comment if it was helpful or useful in any way :)

Profile icon
PYer

Instead of using `eval()` (Don't it is bad practice) you could just do `y = int(x)`. When you divide a number by another, the answer is always a float (With decimal point), which you then can convert into an integer with the `int()` function.

Profile icon
FARHEENPALAGIRI

Why shouldn't I use eval?? Does it not always work??