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?
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.
User avatar
micseydel
 
Posts: 2992
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