Balconies code python | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Balconies code python

Can you please correct my code a=input() list=a.split() b=input() anotherlist=b.split() newlist=[] secondlist=[] for value in list: if type(value)==str: newlist.append(int(value)) for new in anotherlist: if type(new)==str: secondlist.append(int(new)) for mult in newlist: a=mult*mult for anti in secondlist: b=anti*anti if a>b: print('Apartment A') else: print('Apartment B')

19th Jul 2023, 6:12 AM
N G Johnson
N G Johnson - avatar
3 Respuestas
+ 5
N G Johnson , there are 2 issues that prevent the code from working properly. (1) ... for mult in newlist: a=mult*mult for anti in secondlist: b=anti*anti ... newlist and secondlist each contains 2 numbers like [3, 5]. you are running a loop for each with this result: a = mult * mult the result (mult contains the first number of the list) is multiplied by itself and then stored in variable a, then in the second loop iteration (mult now contains the second number of the list) and it replaces the value in variable a. this result is not correct. we have to multiply the first with the second number. to do this, we don't need to run a loop, since our list always contains 2 numbers. we can access the elements by using an index: a = newlist[0] * newlist[1] do this for both lists. the code will now pass the test cases. (2) the second issue is that we have to use ',' as argument for splitting both inputs.
19th Jul 2023, 2:35 PM
Lothar
Lothar - avatar
+ 2
Lothar I removed my answer as it was wrong. Thanks for pointing out the mistake.
19th Jul 2023, 2:49 PM
EAJUDDIN
EAJUDDIN - avatar
+ 1
the issues wrote Lothar already , but your code is very complicated. See mine for that. with a little bit explanations. https://code.sololearn.com/cm8c51KMxkAq/?ref=app
22nd Jul 2023, 8:50 AM
Angela
Angela - avatar