Pregunta

This question regards a homework assignment I'm doing for my programming class. I'm a total beginner when it comes to programming and up until now I've been fine but, in this instance, I'm lost. So, while answering this question, please assume that I'm clueless/stupid as hell because that's how I feel right now lol.

So I'm making a game of "In-Between" and I'm having an issue.

Example of what happens:

Would you like to play in-between [y|n]? y

Die 1: 1 Die 2: 1

Number of chips: 100 Place your bet: 50

Even-steven!

Even-steven! Higher or lower [h|l]? h

Die 3: 10

* You win! *

Die 3: 10

* Sorry - You lose! *

You now have 100 chips! Would you like to play in-between [y|n]?

Here's my code:

if die1 == die2:
    print('\nEven-steven!')
    guess = input('\nEven-steven! Higher or lower [h|l]? ')

    print('\nDie 3:', die3)

    if guess == 'h':
        if die3 > die1:
            print('\n*** You win! ***')
            chipBalance = chipBalance + bet
        elif die3 < die1:
            print('\n*** Sorry - You lose! ***')
            chipBalance = chipBalance - bet
        elif die3 == die1:
            print('\n*** You hit the post - You lose! ***')
            chipBalance = chipBalance - bet

    elif guess == 'l':
        if die3 > die1:
            print('\n*** Sorry - You lose! ***')
            chipBalance = chipBalance - bet
        elif die3 < die1:
            print('\n*** You win! ***')
            chipBalance = chipBalance + bet
        elif die3 == die1:
             print('\n*** You hit the post - You lose! ***')
             chipBalance = chipBalance - bet

I'm sorry that it's really long but I'm just so clueless r/n and would really appreciate ANY help you can give. Allow me to reiterate that I'm very new to this and I don't understand much programming terminology at all so please give me the simplest answers you can. Thanks so much!!!

¿Fue útil?

Solución

A common pattern with these kind of restarts is to assume that the player wants to play the first time and then ask if he/she wants to continue before ending.

play = 'y'
while play == 'y'

    Do your game logic here

    play = input('Would you like to play in-between [y|n]? ')

Hopefully that should show you how to get back on track.

Edit: sorry I saw now that this functionality was already in place. The issue you are having is that you get stuck in loops when you look at what value guess is, instead of looping you should use a if statement when checking what the guess is.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top