3 Replies - 363 Views - Last Post: 01 October 2012 - 07:56 PM Rate Topic: -----

#1 q81101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-September 12

Deal probability

Posted 01 October 2012 - 03:05 PM

def main():

    import random
    # Prompt the use to enter number of times
    times = eval(input("Enter number of time you want to play: "))

    print("Prize", "\tGuess", "\tView", "\tNewGuess")

    # Table layout
    for i in range(1, times +1):
            print(" ", random.randint(1,3), end = '')
            print("      ", random.randint(1,3))

            


main()


I want each column generate random number from 1 to 3. For "views" colummn, the random number can not be the Prize or guess.(ex when i have prize = 2, guess = 2, my view can only be 1 or 3.)

I realize I didn't assign the variable for random, but when I assign prize = random it give me the coulmn with all same number, what can I do to have different random number in each row.

def main():

    import random
    # Prompt the use to enter number of times
    times = eval(input("Enter number of time you want to play: "))

    print("Prize", "\tGuess", "\tView", "\tNewGuess")

    # variables
    prize = random.randint(1,3)
    guess = random.randint(1,3)

    # Table layout
    for i in range(1, times +1):
            print(" ", prize, end = '')
            print("      ", guess)
            
    

 


main()


Is This A Good Question/Topic? 0
  • +

Replies To: Deal probability

#2 q81101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-September 12

Re: Deal probability

Posted 01 October 2012 - 07:30 PM

Never mind I got this one
Was This Post Helpful? 0
  • +
  • -

#3 midknight51  Icon User is offline

  • New D.I.C Head

Reputation: 20
  • View blog
  • Posts: 47
  • Joined: 25-September 12

Re: Deal probability

Posted 01 October 2012 - 07:44 PM

Care to share how you solved it? I thought it had something to do with the seed but I could be wrong.
Was This Post Helpful? 1
  • +
  • -

#4 q81101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-September 12

Re: Deal probability

Posted 01 October 2012 - 07:56 PM

View Postmidknight51, on 01 October 2012 - 07:44 PM, said:

Care to share how you solved it? I thought it had something to do with the seed but I could be wrong.



def main():

    import random
    # Prompt the use to enter number of times
    times = eval(input("Enter number of time you want to play: "))

    print("Prize", "\tGuess", "\tView", "\tNew Guess")
    
    # Table layout
    for i in range(1, times +1):
        prize = random.randint(1,3)
        guess = random.randint(1,3)
        
        print("", prize, end = '')
        print("      ", guess, end = '')


it seem like the random has to be in inner loop
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1