Question

In: Computer Science

I am struggling to write a python script that calculates the average length ,max length shortest...

I am struggling to write a python script that calculates the average length ,max length shortest length and overall average length of of a snake and ladder game. I use python 3
The length is the number the dice is rolled until the max is reached

We need a python script that calculates the number of moves it will take for a single player to reach 100. We have to simulate a snake and ladder game using python language. So one person plays the game several times and will compare the number of moves per each played game for us to be able to come up with the required data

Solutions

Expert Solution

Thanks for the question, here is the code, that plays snake and ladders, Its a starting code for you, The program keeps on playing the game until the user lands in 100. DUring the play it tracks the number of turns and at the end it prints the count.

For solving the max and shortest length, you need to do this experiment a large number of times. and then track the smallest and largest number.

If you need help on this also, please comment and i will assist you. I think you can do it from here.


Below is the code with screenshot.

===========================================================================

import  random
# contains the key values
# for example if user lands to 17 it will take user to 7, if lands on 54: will take user to 34
snakes_dict = {17: 7, 54: 34, 62: 19, 64: 60, 87: 36, 93: 73, 95: 75, 98: 79}
# when user lands in 1 user will be taken to 38, if 4 then 14 like wise
ladder_dict = {1: 38, 4: 14, 9: 31, 21: 42, 28: 84, 51: 67, 72: 91, 88: 99}

place=0
count=0
while place!=100: # here max is 100
    dice = random.randint(1,6)
    place+=dice
    print('You rolled: {} you went to : {}'.format(dice,place))
    # check the place for a snake or ladder
    if place in snakes_dict.keys():
        place = snakes_dict.get(place)
        print('Oops. There was a snake. You went down to {}'.format(place))
    elif  place in ladder_dict.keys():
        place = ladder_dict.get(place)
        print('Congrats. You got a ladder. You climbed to {}'.format(place))

    if place>100:place-=dice
    count += 1

print('It took {} turns to reach to 100'.format(count))

==============================================================


Related Solutions

Write a python script to calculate the average length of the game shortest game , longest...
Write a python script to calculate the average length of the game shortest game , longest game and the overall average length of a snake and ladder game The game length is the number of throws of the die. We are asked to write a python script which calculate that together with the average
Write a python script to calculate the average length of the game, Shortest game, longest game...
Write a python script to calculate the average length of the game, Shortest game, longest game and overall length of the game we need a python script that calculates the average length of a snake and ladder game. ie the number of moves it takes a single player to win the game. Then you run the game several times and will compare the results to come up with the required data(length of the game and number of moves )
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
Hi there I need to write an ethic issue in technology but I am struggling to...
Hi there I need to write an ethic issue in technology but I am struggling to choose a topic. I am asking about the possibility of "Ethical issues" topics that is tread common in technology. Would anyone can give me some options to choose from. Thank you.
3. Write a script that generates two random numbers between -5 and 25, calculates their average,...
3. Write a script that generates two random numbers between -5 and 25, calculates their average, and if the average is greater than 10 then prints “High Average” else prints “Low Average”. You can use $RANDOM to generate the random numbers. 4. Write a script using the for-loop construct that counts the number of directories looping through the files in the directory name provided by the user on a prompt by the script.
I am confused with Python I have to write a specification for an email address. In...
I am confused with Python I have to write a specification for an email address. In one string a valid email address and the other without a valid email address. Ex: print(text_match("My teacher’s email is [email protected]")) print(text_match("My teacher has no email address"))
I am comfortable with structures that contains one item per variable. But i am struggling to...
I am comfortable with structures that contains one item per variable. But i am struggling to manage structure that contains multiple items in one variable (within a matrix). it's in C language. for example this structure :    struct resume{ char *name; char *job; char school*; int counter_resume; }resume; i want to create functions that are able to dynamically allocate memory so it can add multiple persons resume without knowing how many they are going to be in the beginning....
Write a Python program that computes certain values such as sum, product, max, min and average...
Write a Python program that computes certain values such as sum, product, max, min and average of any 5 given numbers along with the following requirements. Define a function that takes 5 numbers, calculates and returns the sum of the numbers. Define a function that takes 5 numbers, calculates and returns the product of the numbers. Define a function that takes 5 numbers, calculates and returns the average of the numbers. Must use the function you defined earlier to find...
Hello, I am attempting to write a program which calculates the amount of fence pieces needed...
Hello, I am attempting to write a program which calculates the amount of fence pieces needed to achieve a certain distance. The program should take in the amount of fencing needed from the user, then ask them the size of the smaller piece. The fencing is to be made up of two sizes of fencing, the smaller being two feet less than the larger. Then, the program will tell the user how many of each piece is needed. However, I...
Assembly Question: I am trying to annotate this code and am struggling to understand what it...
Assembly Question: I am trying to annotate this code and am struggling to understand what it is doing. Can someone please add comments? .data .star: .string "*" .line: .string "\n" .input: .string "%d" .count: .space 8 .text .global main printstars: push %rsi push %rdi _printstars: push %rdi mov $.star, %rdi xor %rax, %rax call printf pop %rdi dec %rdi cmp $0, %rdi jg _printstars mov $.line, %rdi xor %rax, %rax call printf pop %rdi pop %rsi ret printstarpyramid: mov %rdi,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT