## 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?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
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