0

Is this possible with pyhton? If it is, how can you do it?

def raise():
    raise = raw_input('Do you really want to raise? y/n')
    if raise == 'y':
        bet = bet+1
        return # Should RETURN to play(), after raise()
               # Like "goto LABEL"
    else:
        return

def play():
     bet = 1
     print 'The computer did a bet of 1 dollar.'
     print 'I raise.'
     raise()  # The 'LABEL'
     print 'The bet now is', bet
     print 'End of the test."

Edited by Hawkeye Python: n/a

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Paul Thompson
1

Here is your code, slightly modified to work. I have passed bet in as a parameter and returned it; and renamed the function to something legal (I recommend using a better name than my choice). Note also the space after the y/n: Not necessary, but much prettier in my opinion.

def rraise(bet):
  rraise = raw_input('Do you really want to raise? y/n ')
  if rraise == 'y':
    bet = bet+1
  return bet
#
def play():
  bet = 1
  print 'The computer did a bet of 1 dollar.'
  print 'I raise.'
  bet = rraise(bet)
  print 'The bet now is', bet
  print 'End of the test.'

play()
0

You also need some error checking, it's good practice.
Example:

rraise = raw_input("Do you really want to raise? y/n ')
if rraise == 'y':
  bet += 1
elif rraise == 'n':
  pass
else: print "y or n please..."
return bet
0

Mark thread is solved has moved. You can now find it as a link at the top. Use ctrl+F and search for solved and you should find it. It is next to the bit that says "Python Discussion Thread View First Unread"

Just an FYI for anyone who needs to know.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.