0
Where did I go wrong?
Desperate help please https://code.sololearn.com/cMs0Ksh3SCe4/?ref=app
12 odpowiedzi
+ 4
I think you posted the same question twice. In the other thread, there are already answers. Didn't it help?
+ 3
Dr. Exceptional
if all(x[i] * x[i] == y[i] for i in range(len(x))):
print("true")
else:
print("false")
+ 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.
+ 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?
+ 1
Thanks man
+ 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.
+ 1
Dr. Exceptional, may be you put your code in a new post, so that er can see whats happening?
+ 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
0
And how shud I do that?
0
Lisa is okay thanks
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”
- 2
Hello