+ 1
Tuple Hadouken : I cannot tell what this is, in Python 3.11 (problem likely not due to it being in 3.11 though)
Hi, I have this code for this Blackjack exercise that I'm doing. Problem better visible in code. (it's a bit long, I just put part of it) In the supposedly representative (apparently not) case, I not only got the same result in both Python versions, but also the intended one. (Worked with a list too) So I don't think it's the Python version that's the problem, either. Can you look at this and see what I really mean? (Trimmed question, I hope it's less tedious now) https://code.sololearn.com/cVZxjdAqu6kk/?ref=app
4 Respuestas
+ 2
I tested your function on Python 3.11 (repl.it) with these inputs:
calculate_stakes(['insure', 'yes'], 200)
Result: (200, 100.0)
Seems like expected.
https://replit.com/@TiborSanta/Python-311-Test#main.py
+ 3
For me it was not clear from your code, what WAS the intended result. A tuple of two numbers, or a tuple of a number and another tuple.
One remark:
if ("split" or (action[1] == "yes"))
This condition is always true, because a nonempty string is evaluated to True.
Since you only posted a fragment of the code, it's not possible to see what is happening before the actual function call and what kind of values you are passing. Can you reproduce the issue on the Sololearn playground?
Maybe one hint about syntax
(x) # evaluates to x
(x,) # evaluates to a tuple containing only x
(x,y) # evaluates to a tuple of two values
x,y # evaluates to a tuple of two values
+ 2
Tibor Santa So somehow f(g(x), y) gives tuple inside a tuple while
f(constant, y) returns just one tuple with two numeric values.
I'll try to find out why. This helps. Thanks 😊
+ 1
Tibor Santa The intended result was the one in the simpler code, x itself evaluating to a tuple of two values (x, y)
Variable bound to integer gets to be assigned a tuple where this integer and its half are the tuple values, which seems to work in the bottom code, but not in the code I partially shared.
About the or bit: In my code what gets evaluated is controlled by the argument of the inner function, it's there to remind me to get back to it once I code the split condition elsewhere. But thank you, for the warning, because I realize I've been lazy with commenting, causing more confusion where I've already confused myself.
I will try to reproduce it some time. Can I tag you then?
Also: It's always much appreciated at least by me when we're clued in on the fact that our questions are unclear. Thank you.