Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i turn split input into int?

Heres what i have so far. What im trying to do is ask the user for an expression, they input something like "1 + 1" and its split into x, y, and z so
X would be 1, Y would be + and Z would be the second 1.
Im sure there may be several issues but the main one im having right now is converting their input into an int. im still very very new with this this is literally just an intro to python course so any help is welcome. tia.

x, y, z = input("Expression: ").split()

if y == "+":
output = x + z
print(output)

elif y == "-":
output = x - z
print(output)

elif y == "*":
output = x * z
print(output)

elif y == "/":
output = x / z
print(output)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can try for this:

x, y, z = input("Expression: ").split()

x = int(x)
z = int(z)

if y == "+":
    output = x + z
    print (output)

elif y == "-":
    output = x - z
    print(output)

elif y == "*":
    output = x * z
    print(output)

elif y == "/":
    output = x / z
    print(output)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading