project: https://www.codecademy.com/practice/projects/games-of-chance
task 4 cho han game:
the user should type ‘odd’ or ‘even’, but if they use ‘Odd’ then code no longer true, how to use. (the answer didn’t talk about this) , i also tested many ways but not work.
#4. cho han
def cho_han(guess,bet):
#Makes sure your bet was above 0
if bet <= 0:
print("------------------")
print("Your bet should be above 0.")
print('Your money is',money)
return 0
print("------------------")
print('let guess, you guess',guess)
result1=random.randint(1,6)
result2=random.randint(1,6)
#print result:
if (result1+result2)%2==0:
print('result is even')
else:
print('result is odd')
#win lose
if ((result1+result2)%2==0 and guess=='even')or ((result1+result2)%2==1 and guess=='odd'):
print('you won', bet,'dollars')
#elif (result1+result2)%2==1 and guess=='odd':
#print('you won', bet,'dollars')
return bet
else:
print('you lost', bet, 'dollars')
cho_han('Odd',40)
If you convert what they typed to all lower case, then it’ll always be all lower case
Better if you think about what you would need to do instead of testing random things. Pick one, and then think about how you can do that specific thing.
A parameter is a variable same as any other, the only difference being that they get assigned when the function is invoked, after that they’re the same.
If you were trying to put code inside the parameter list then yeah you’d have a problem, there’s nothing saying you can do that.
But you can put code in the body of the function, and you’re free to do whatever you want with the values that were given to your function.