My code receives two lines of input and splits those into lists. The result should look like:
input
4 6
2 4
output
2.0 1.5
I'm very new to coding, so my code isn't the most efficient, but here it is:
U = list(input().split(" "))
I = list(input().split(" "))
for z in range(len(U)):
for x in U[z]:
for y in I[z]:
R = float(x) / float(y)
print(round(R, 1), end=" ")
When I remove for x in U[z]: it works perfectly fine, except it prints every possible result. It also works fine with integers without removing the z loop. The full code for floats, however, prints ValueError: could not convert string to float: '.'. Is there a way to fix this without messing with the code too much?
2.0 1.5, no errors. The input I used was4 6, then hit Enter, then2 4and Enter againlist(),split()always returns a list..split()returns alist, so there's no reason to uselist()there. Also, you can replace the 3forloops with one by usingfor x,y in zip(U,I):.