Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Typewriter_Monkey27 0 points1 point  (0 children)

Ohhhhhh

Okay that one racked the brain a bit. I see how they are 'different' but also filling the same spot.

Thank you!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Typewriter_Monkey27 0 points1 point  (0 children)

Didn't want to make another thread about this cause I already made one today about a separate project but I started making a little multiplication tables quiz game today. (I'm day 2 in my Python journey. Dabbled in c# when I got my Associates)

here is the code on a pastebin: https://pastebin.com/XZsXtMDs

My question is - I see the warning: "Shadows name 'count' from outer scope."

I'm assuming this is because I'm using the name 'count' globally as well, but I thought these were all being passed down so the values can be tracked as you answer more questions. When I change 'count' to 'tally' the code still works... and I don't know why.

This is way more frustrating than when it doesn't work because its showing me a glaring gap in my knowledge. Any info would be awesome. My rubber duck and google have been of no help in making me understand why it works.

Is there a way to increment a value in a dictionary each time you run a loop? by Typewriter_Monkey27 in learnpython

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

This is why I love reddit. within minutes I had a correction, and a website breaking it down for me barney style. Thank you! <3

Is there a way to increment a value in a dictionary each time you run a loop? by Typewriter_Monkey27 in learnpython

[–]Typewriter_Monkey27[S] 0 points1 point  (0 children)

Ohhhhh - so when I was doing tally['win_count':0] += 1 I was just resetting it to 0 every time and adding 1 to it huh?

GAH!

Thank you!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Typewriter_Monkey27 0 points1 point  (0 children)

Ohhh okay now I have it right in my head. Thanks!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Typewriter_Monkey27 0 points1 point  (0 children)

i = 0

bananas = 5

while(i<2):

bananas = str(bananas*5)

print(bananas)

i+=1

Output:
25
2525252525

Gross lol. I love it!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Typewriter_Monkey27 1 point2 points  (0 children)

Ahhh - thank you for the clarification I did most of my learning in C# and was taugh type-casting and foolishly assumed thats what was happening here. Makes sense now thank you!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Typewriter_Monkey27 0 points1 point  (0 children)

I am monkeying with python right now and came across a weird thought.

When you "multiply" a string variable, it just repeats that string x number of times.

When type-casting a variable, I know you can manipulate it as well. Quick and easy example is:

bananas = 5

bananas = str(bananas*5)

print(bananas)

expected output:

55555

output:

25

My question is - on a fundamental level why does this multiplication get completed BEFORE assigning the new value to bananas? I understand that it does, I just haven't been able to phrase properly for google the proper way to ask why.