0

okay so I am very very new to python and am making a dice game i tried to concatenate using a string and a random number using the random randint function but it just displays a long no sense error message for example: please excuse my indentation I am trying to make a program which simulates rolling a fair sided dice over agian until 50 is reached

3
you chose the number<bound method Random.randint of <random.Random object at 0x02804790>>woop
5
you chose the number<bound method Random.randint of <random.Random object at 0x02804790>>woop
2
you chose the number<bound method Random.randint of <random.Random object at 0x02804790>>woop
2
you chose the number<bound method Random.randint of <random.Random object at 0x02804790>>woop
4
you chose the number<bound method Random.randint of <random.Random object at 0x02804790>>woop

Here is my code can anyone help me so that the code stops once the all the dice numbers added add up to 50:

    import random
     score = 0
     poss_ans = 'yes'
     poss_ans1= 'no'
     roll_1 = 0
     count = True
     for i in range(50):
       one = 0
        two = 0
       three = 0
       four = 0
        five = 0
        six = 0
        number_6=raw_input("do u wanna play")
       if number_6 == poss_ans:
     print("okay")
      elif number_6 == poss_ans1:
     print("weirdo")
    score = 0
   while count < 50:
     print(random.randint (1, 6))
      print ("you chose the number" + str(random.randint) + "woop")
        count += 1
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
  • related: http://stackoverflow.com/questions/1349332/python-passing-a-function-into-another-function – NightShadeQueen Jul 15 '15 at 17:06
  • 1
    Or, in other words, that is what you're doing. I'm not quite sure what you're trying to do, but currently you're passing the function `random.randint` to `str()` – NightShadeQueen Jul 15 '15 at 17:07
  • Welcome to Stack Overflow! Please identify the [shortest program necessary to reproduce the problem](http://stackoverflow.com/help/mcve) before posting. – galath Jul 15 '15 at 17:12

4 Answers4

1

You should be concatenating the number that random.randint returns like that: "Hello"+str(random.randint(1,6)).

Your problems are because you're trying to convert a function to a string. That's possible. I got the following in Python 2.7:

>>>str(random.randint)
 '<bound method Random.randint of <random.Random object at 0x1653720c>>'
ForceBru
  • 43,482
  • 10
  • 63
  • 98
0

You can use the format method

print ("you chose the number {} woop".format(random.randint(1,6))
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
0

You can also use:

print ("you chose the number" + " %d "%random.randint(1,6) + "woop")

random.randint(a,b) takes parameters a and b which are the range of the random number generated including both a and b.

bninopaul
  • 2,659
  • 4
  • 15
  • 22
0

If you want to stop while loop once all the dice numbers add up to 50, you can use this:

    dice_list=[]

    while count < 50:
         dice_number = random.randint(1,6)
         print(dice_number)
         print ("you chose the number " + str(dice_number) + " woop")
         dice_list.append(dice_number)
         count = sum(dice_list)
Kristian
  • 36
  • 4