Code doesnt work as expected to


When I ask the program second time' wanna play again'? and enter 'Y' as input. It doesnt call roll_dice() function again. Instead, it prints 'you are free to leave'..

I expect the function to roll dice again which it doesnt!!

"""This program rolls a pair of dice and adds both values then asks user to guess the number and compares it to original value. If the user's roll is greater than total value of dice roll, user wins and vice versa. Also inform user"""

from random import randint
from time import sleep

def get_user_guess():
  	user_guess = int(raw_input('Guess number'))
  	return user_guess

def roll_dice():
  number_of_sides= int(raw_input('please enter number of sides a dice should have'))
  print 'Rollingaaaa....'
  first_roll= randint(1,number_of_sides)
  second_roll= randint(1, number_of_sides)
  roll_dice= first_roll + second_roll
  max_val= number_of_sides *2
  print'The max possible value is from 1 to ' + str(max_val)

  my_guess= get_user_guess()
  print 'waiting for your luck to decide.. hehehe'
  if my_guess> max_val:
      print 'Guess invalid'  
      print'The first roll is %d' % first_roll
      print'The second roll is %d' % second_roll
      print'The total is %d ' % roll_dice
      if my_guess>roll_dice:
          print'you won'
          print'you lost' 


second_ask = str(raw_input('wanna play again?'))

if second_ask == 'y or Y':
    print'you are free to leave'


if you want to play again, you now have to enter y or Y, that doesn't make much sense

or shouldn't be part of the string, its a keyword in python and you have to compare at both sides of the or operator


you are a life saver!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.