Question: I have some code here in Java, can someone rewrite this to Python--I dont know the syantx of Python yet and I am still learning.

I have some code here in Java, can someone rewrite this to Python--I dont know the syantx of Python yet and I am still learning.

Thank you, will thumbs up.

import java.util.Random;

public class MontyHall {

public static void main(String[] args) {

int switchWins = 0;

int stayWins = 0;

Random gen = new Random();

for (int plays = 0; plays < 32768; plays++) {

int[] doors = { 0, 0, 0 };

// 0 is a goat, 1 is a car

doors[gen.nextInt(3)] = 1;

// put a winner in a random door

int choice = gen.nextInt(3);

// pick a door, any door

int shown;

// the shown door

do {

shown = gen.nextInt(3);

// don't show the winner or the choice

} while (doors[shown] == 1 || shown == choice);

stayWins += doors[choice];

// if you won by staying, count it

// the switched (last remaining) door is (3 - choice - shown),

// because 0+1+2=3

switchWins += doors[3 - choice - shown];

}

System.out.println("Switching wins " + switchWins + " times.");

System.out.println("Staying wins " + stayWins + " times.");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!