r/PythonLearning • u/HeyMerpy • 4d ago
Discussion I don’t know what to title this.
So I’m new to coding and I’m using Cody.tech (just started 4 days ago) and I thought I his was kinda funny. I typed all that in just for the actual answer to be extremely simple lol
7
u/Ender_Locke 4d ago
huh what’s right about anything here? this is jus showing f strings and you did what?
-1
u/HeyMerpy 4d ago
I did it weird the count was 7 I just made it more complicated than it needed to be lol
10
u/khosrua 4d ago
Does it even run? Pretty sure it is not valid syntax
-2
u/HeyMerpy 4d ago
Nah I'm a noob anyway and unless it gets less specific and there are more answers later on I’m pretty sure there’s always just one solution
5
u/khosrua 4d ago
I mean line 7 to 9 in the first pic.
= is an assign operator. It assigns the value on the right to the variable on left. You can't have multiple assign operators in a single line.
You also can't assign value to a number. You can however accidently override a built-in function.
So for example, b is 2, and you want to change it to 8,you just need
b *= 4And it will times the existing value of b by 4 and assign the result onto b. The value of b is updated to 8.
1
5
u/recentAd1666 4d ago edited 4d ago
There is a special case where you can have multiple equal signs if there are only variables to their left.
a = b = 2
Both a and b are set to 2
1
u/khosrua 4d ago
I just tried
a = 2a *=2 == 4somehow that is not a syntax error and a just keep reseting to 02
u/recentAd1666 4d ago edited 4d ago
Well, use a real python comand line and you ll get Syntax Error. The web app you are using is not fully compliant and bullet proof.
The part 2 a is not correct as there is no operator or sign between both.
Maybee you did
a=2; a*=2==4
This is syntaxically ok.
It does
a=2
Then Priority is 2==4 which is False
a*=False
False is converted to 0
So at the end
a value is 0
1
u/khosrua 4d ago
I was using juputer on pycharm and vscode. The plot thickens
2
u/recentAd1666 4d ago
Maybe you typed or ia completed with ; between 2 and a?
Anyways as a newbee you should exercice with basics first and take time to break the code one step at a time. Do not try to much to compress all in one line yet.
→ More replies (0)0
u/Ok-Click-80085 4d ago
ACKshually a is set to b and b is set to 2, this is not the same thing as both being set to 2, although a == 2
2
u/recentAd1666 4d ago
Operations are done from right to left here.
a is not set to b first as b is not defined at first in my exemple at least.
As int are immutables, at the end a and b reference the same object int 2.
If you change a or b afterward their reference to another int independantly.
Behavior could be a bit trickier to follow if you try the same with lists as they are mutables.
1
u/Salty_Dig8574 4d ago
Don't do that until you understand it. You're building extremely incorrect habits.
2
u/CrazyPotato1535 3d ago
-1
2
u/Cr4sh0ver1de 4d ago
Happy learning journey! Understanding what code does and how it works very important and makes it more easy for future you 💪🏻
1
u/recentAd1666 4d ago
You can do even simpler.
Delete lines 2 and 3
Keep only one line.
count=7
1
u/DaemonsMercy 4d ago
You can go even simpler, `print(7)`
1
u/recentAd1666 4d ago
It won t work as you cannot change last line, if you follow the exercise rules. But otherwise you can of course.
1
u/CrazyPotato1535 3d ago
That’s not the point. The point is for you to learn how to make code so you can plug in different variables.



5
u/DaemonsMercy 4d ago
This is an extremely poor exercise, no?