Random Function with Modulus

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

Random Function with Modulus

Postby plastikman808 » Sat May 11, 2013 3:58 pm

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.
Reason: Added code tags.
plastikman808
 
Posts: 1
Joined: Sat May 11, 2013 3:54 pm

Re: Random Function with Modulus

Postby micseydel » Sat May 11, 2013 8:19 pm

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!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1269
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Random Function with Modulus

Postby setrofim » Sat May 11, 2013 8:33 pm

Unindent the second if statment one level.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 7 guests