## Random Function with Modulus

This is the place for queries that don't fit in any of the other categories.

### Random Function with Modulus

Hi board,

I am trying to get a print out when 2 die are rolled. However the results are not what i expected?? Can someone please help

Code: Select all
`for x in range(1,30):   throw1=random.randint(1,6)   throw2=random.randint(1,6)   total=throw1+throw2   if total%2==0:      print('you threw a even number')      if total%2==1:         print('you threw an odd number')`

The Results are this:
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number
you threw a even number

Thanks
Last edited by micseydel on Sat May 11, 2013 8:15 pm, edited 1 time in total.
plastikman808

Posts: 1
Joined: Sat May 11, 2013 3:54 pm

### Re: Random Function with Modulus

Before you post again, read this.

I don't understand what the problem is with your code, And you're simulating two die rolls every time. What result do you want instead?
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from

micseydel

Posts: 2250
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Random Function with Modulus

Unindent the second if statment one level.
setrofim

Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm