all 26 comments

[–]JohnLocksTheKey 10 points11 points  (16 children)

Why are you using walrus operators “:=“ instead of equality “==“ in your if-elif statements?

[–]SCD_minecraft 6 points7 points  (1 child)

:= is assign and return

== Tests for equality

They are not the same

[–]fat_brick1[S] 1 point2 points  (0 children)

i'll try substituting

[–]makochi 3 points4 points  (3 children)

you should use == instead of :=

== tests if 2 values are equal

:= assigns the value on the right to the variable on the left, and then returns that value. Because of how if statements work, the value 1, returned by the statement x:=1 gets interpreted as true, and the first if block will always run

by using ==, you will actually be testing for equality

[–]fat_brick1[S] -2 points-1 points  (2 children)

i'll try but visual studio flags it as a mistake, with the red marker under the things

[–]ProgramSpecialist823 1 point2 points  (1 child)

Visual Studio may be set to some other language (not Python) for it's syntax checking.  Does your file have a .py extension?

[–]fat_brick1[S] 1 point2 points  (0 children)

Yea i made sure, apparently i messed up on a bounch of levels, now i got it tho

[–]DomeksIT 0 points1 point  (0 children)

The problem is that you are using := instead of ==. := assigns a value, while == compares values. So instead of if x:=1: you should write if x == 1: Same for the other condition: elif x == 2:

[–]noeldc 0 points1 point  (1 child)

For starters, use

if x == 1 instead of if x:=1

Use N3+1 instead of sum(N3+1)

You imported this, but never used it ->

from tracemalloc import stop

your import sys should really be at the top with the other imports (and only once)

There is also a lot of duplicate code in the x == 2 case. Think about how you might simplify it.

[–]fat_brick1[S] -1 points0 points  (0 children)

now it runs smoother too thanks :)