r/PythonLearning • • 4h 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

0 Upvotes

15 comments sorted by

2

u/Cr4sh0ver1de 3h ago

Happy learning journey! Understanding what code does and how it works very important and makes it more easy for future you 💪🏻

1

u/Ender_Locke 4h ago

huh what’s right about anything here? this is jus showing f strings and you did what?

0

u/HeyMerpy 4h ago

I did it weird the count was 7 I just made it more complicated than it needed to be lol

5

u/khosrua 3h ago

Does it even run? Pretty sure it is not valid syntax

1

u/HeyMerpy 3h 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 

2

u/khosrua 3h 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 *= 4

And it will times the existing value of b by 4 and assign the result onto b. The value of b is updated to 8.

2

u/recentAd1666 3h ago edited 3h 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 3h ago

I just tried a = 2 a *=2 == 4 somehow that is not a syntax error and a just keep reseting to 0

1

u/recentAd1666 3h ago edited 2h 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 3h ago

I was using juputer on pycharm and vscode. The plot thickens

1

u/recentAd1666 2h 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

2

u/Maqi-X 3h ago • Bravo

You can use {count = } in f-strings

1

u/recentAd1666 3h ago

You can do even simpler.

Delete lines 2 and 3

Keep only one line.

count=7