lundi 27 novembre 2017

cant get random.shuffle to workpython random.shuffle()

Right now I am trying to do a piece of code for the Monty Hall problem

I have some code that I am trying to fix and then enhance

This is one thing that I am stuck on:

I am trying to change the way the door at which the prize is chosen by using random.shuffle(), I have to use random.shuffle(), not anything else.

How would I do this?

What I have now does not work for that. if I put print(random.shuffle(door))', All it gives me isNone` as an output

import random
door = ["goat","goat","car"]

choice = int(input("Door 1, 2 or 3? "))

otherDoor = 0
goatDoor = 0

if choice == 1:
    if door[1] == "goat":
        otherDoor = 3 
        goatDoor = 2
    elif door[2] == "goat":
        otherDoor = 2
        goatDoor = 3  
elif choice == 2:
    if door[0] == "goat":
        otherDoor = 3
        goatDoor = 1
    elif door[2] == "goat":
        otherDoor = 1
        goatDoor = 3
elif choice == 3:
 if door[0] == "goat":
     otherDoor = 2
     goatDoor = 1
 elif door[1] == "goat":
     otherDoor = 1
     goatDoor = 2

switch = input("There is a goat behind door " + str(goatDoor) +\
               " switch to door " + str(otherDoor) + "? (y/n) ")

if switch == "y":
    choice = otherDoor

if random.shuffle(door) == "car":
    print("You won a car!")
else:
    print("You won a goat!")

input("Press enter to exit.")


This is one of the sites that I used to try and figure out the answer I need, but I could not find anything.

Heading




Aucun commentaire:

Enregistrer un commentaire