As shown below, I'm providing the user with an option to spend points, I'm ensuring that the input contains either of 'y yes n no'. If the user would like to spend points he's prompted to select a number which differs the assignment of v
, I'm ensuring the input is a number using .isdigit()
. If the user wouldn't like to spend points v
is simply assigned to 0.0
while True:
choice = raw_input('\nSpend points?')
if choice.lower().strip() in "y yes n no".split():
while True:
if choice.lower().strip() in "y yes".split():
c = raw_input('Enter Value 1-6: ')
if c.isdigit() and int(c) <= 6:
if choice.lower().strip() in "y yes".split():
if c == '1':
v = 0.3
if c == '2':
v = 0.25
if c == '3':
v = 0.2
if c == '4':
v = 0.1
if c == '5':
v = 0.05
if c == '6':
v = 0.75
break
if choice.lower().strip() in "n no".split():
v = 0.0
break
else:
continue
else:
continue
print v
However, although the code works fine, after v
seems to be printed successfully, the code will continue looping back to 'Would you like to spend credits?'
I believe the problem lies with my break
statement, but I'm not sure where it's supposed to go.
Aucun commentaire:
Enregistrer un commentaire