#๐Ÿ”’ I don know if what i did is correct or bad

122 messages ยท Page 1 of 1 (latest)

strange wren
pure hatchBOT
#

@strange wren

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tulip quest
#

I don't have time to do a full review, but the code in the screenshot is not legal Python.

naive schooner
tulip quest
#

To check equality, you need ==. = is for assigning a value, and isn't legal where you have it.

strange wren
#

yes i forgor

#

but is the logoccorrect?

#

logic

strange wren
naive schooner
naive schooner
tulip quest
#

You can't just write code and then guess if it's functional. You need to be running and verifying your code as you write it.

strange wren
naive schooner
strange wren
naive schooner
#

that means dont change anything

#

just run it

strange wren
#

it says

naive schooner
strange wren
naive schooner
# strange wren

what is this? are you doing something like codewars or leetcode? or are you doing some online course study?

naive schooner
#

ah ok

naive schooner
naive schooner
#

My guess is that you have to execute each test explicitly in the code

strange wren
#

i mean call the function

#

did i just define it only?

naive schooner
strange wren
naive schooner
naive schooner
# strange wren

above this, there is a black background console. What does it show?

naive schooner
#

You havn't changed your code?

strange wren
#

I did

#

i mean i didnt

#

i just changed the ==

naive schooner
#

Your code is constantly being tested to see if its Python valid and that shows in the console on the right

strange wren
#

No๐Ÿ˜ญ

naive schooner
#

so if you had the = in that if condition, it should show that error message in the console

strange wren
#

it doesnt

naive schooner
#

instructions, code, console and the test result

#

all in one

strange wren
naive schooner
# strange wren

Strange but ok and now click on the "Run the Tests" button and show me a new screenshot after clicking it

strange wren
naive schooner
#

hmm

naive schooner
# strange wren

copy your code, paste it here, then click "Reset this lesson" button, then paste your code back in, and click "Run the Tests" button.

subtle plover
#

lines 5 and 6 aren't indented properly

#

there's an extra space

naive schooner
naive schooner
#

freecodecamp's IDE autoruns the script to check if its valid Python code. So I don't know whats wrong with OP's

strange wren
#

def most_frequent(arr):
timesarray = []
for elements in arr:
totaltimes = 0
flag = False
diffrence = len(arr) - elements
for existence in range(diffrence):
if arr[elements] == arr[existence]:
flag = True
if flag == False:
for elements2 in arr:
if arr[element] == arr[elements2]:
totaltimes = totaltimes + 1
timesarray[element] = totaltimes
highestindex = 0
for elements3 in timesarray:
if timesarray[elements3] > timesarray[highestindex]:
highestindex = elements3
return arr[highestindex]

return arr

pure hatchBOT
#

Hey @strange wren!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
strange wren
#

no its still the same

naive schooner
strange wren
naive schooner
#

thats not right...

strange wren
#

yes its not

naive schooner
#

it should at least show the syntax error

strange wren
#

it doesnt show

subtle plover
#

which web browser are you using?

naive schooner
strange wren
naive schooner
# strange wren

I think something is blocking your script running in freecodecamp. Can you open up devtools?

#

Press F12

#

And show me the Console tab

strange wren
naive schooner
#

๐Ÿคฆโ€โ™‚๏ธ

subtle plover
#

lmao

strange wren
#

ill js download the app ahh๐Ÿ˜”

naive schooner
# strange wren

ok so now that button makes sense. When you press that "Run the Tests" button, it should revert back to black button. The button looks like its still being pressed.

subtle plover
#

'k, now let's get to debugging the actual code

strange wren
#

๐Ÿ˜”

naive schooner
strange wren
subtle plover
#

line 6 will throw an error in test case 1
it's doing len(arr) - elements but elements will take on the value of letters

#

!e 4 - "a"

pure hatchBOT
# subtle plover !e 4 - "a"

:x: Your 3.14 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 1, in <module>
003 |     4 - "a"
004 |     ~~^~~~~
005 | TypeError: unsupported operand type(s) for -: 'int' and 'str'
subtle plover
#

the first thing it will do is throw an error

strange wren
#

btw its my first time in python, im switching languages ๐Ÿ˜ญ

subtle plover
#

no worries

#

you can chain functions together to make the code a bit more readable

for index in range(len(arr)):
subtle plover
#

How's your progress?

strange wren
subtle plover
#

I'm getting confused about most of the code on lines 7 through 14

#

I know you're counting how many times it appears, but the how eludes me

strange wren
#

if ot exists then i dont count it

#

if it doesnt exist then i count how many times ot exists in the array and i store it

#

if the array is [a,b,a,d,a] then when im looping i dont want to count for the 3rd element in the array bcz a is the first element already and i counted for it already

subtle plover
#

ok, say I feed your function the array: [1,1,1,2]
it will create a timesarray that looks like: [1,2,3,1]?

strange wren
#

i want the times array to look like[3, , , 1]

naive schooner
#

but try and finish this one first though

strange wren
subtle plover
#

So, the simple way of solving this would be to just count the items in the array repeatedly.
That way, an input of: [1,1,1,2]
Becomes timesarray = [3,3,3,1]

Your solution is maybe more optimized, but still has O(nยฒ) complexity

strange wren
#

ill do that

#

thanksss

naive schooner
#

Done. Did it without collections or counter. Feels dirty using 2 loops

#

pseudocode wise, I used a dictionary to keep count of each unique element in the array and then loop the dictionary to find the highest count. I'm pretty sure there are better ways to do it

subtle plover
#

I'm tempted to do it in one line

pure hatchBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.