0

Where did I go wrong?

Desperate help please https://code.sololearn.com/cMs0Ksh3SCe4/?ref=app

9th May 2020, 12:58 PM
Calvin Capstone
Calvin Capstone - avatar
12 Réponses
+ 4
I think you posted the same question twice. In the other thread, there are already answers. Didn't it help?
9th May 2020, 1:40 PM
Lisa
Lisa - avatar
+ 3
Dr. Exceptional if all(x[i] * x[i] == y[i] for i in range(len(x))): print("true") else: print("false")
9th May 2020, 7:53 PM
Russ
Russ - avatar
+ 2
You are trying to multiply a tuple with itself. But actually you would like to square each element within that tuple (?) Further you would need to compare for each squared element of x if it is in y.
9th May 2020, 1:15 PM
Lisa
Lisa - avatar
+ 2
I am assuming you want to compare x[0]*x[0] == y[0], x[1]*x[1] == y[1],... In this case you can use a loop that iterates through the 2 lists. If you are familiar with for loop, you can try to use this, otherwise you can also use a while loop with a counter variable. I would encourage you to try this, it's not that difficult! If you struggle you can back to here and ask us. BTW, The elements in the second list are made that they all fit to the condition that you check 🙂 Happy coding! ??? What does the title of your sample code 'prime numbers' mean?
9th May 2020, 1:43 PM
Lothar
Lothar - avatar
+ 1
Thanks man
9th May 2020, 1:44 PM
Calvin Capstone
Calvin Capstone - avatar
+ 1
Curious at Lothar , I loop through both lists and got “true” printed out, 13 times and got index error, how can I write the code, for “true” to be printed once if every value in y corresponds to the square of values in x and print false if I change one value in y that does not correspond to a value in x.
9th May 2020, 7:27 PM
Jibril Balogun
Jibril Balogun - avatar
+ 1
Dr. Exceptional, may be you put your code in a new post, so that er can see whats happening?
9th May 2020, 7:36 PM
Lothar
Lothar - avatar
+ 1
That's because you put the if inside a for loop iterating over x - hence your 13 trues. https://code.sololearn.com/cUjv0Mg4CZBK/?ref=app
9th May 2020, 8:59 PM
Russ
Russ - avatar
0
And how shud I do that?
9th May 2020, 1:36 PM
Calvin Capstone
Calvin Capstone - avatar
0
Lisa is okay thanks
9th May 2020, 1:44 PM
Calvin Capstone
Calvin Capstone - avatar
0
Russ , I am getting 13 true’s or 13 false’s depending on the condtion set, I just need an output of one true or one false. Posted the reviewed code on my code bits titled “ Numbers and Squares”
9th May 2020, 8:40 PM
Jibril Balogun
Jibril Balogun - avatar
- 2
Hello
10th May 2020, 9:16 PM
alain monga paluku