#πŸ”’ problem about loops and if statements

32 messages Β· Page 1 of 1 (latest)

tiny lily
#

heres the code

torpid cragBOT
#

@tiny lily

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tiny lily
#

play_again = input("Tekrar oynamak ister misin? (E/H): ").upper()

        if play_again == 'E':
            continue
        elif play_again == 'H':
            break
        while play_again != 'E' or 'H':
            pass
#

thats the code

#

the thing I want to do is

#

if the input that user gave us = E continue playing game (thats a part of a slot game I can give the whole code if you need)

#

if it = H stop the code,game

#

but if its neither

#

like it is G

#

or 7

#

or giraffe

#

it will ask the same question

#

until it gets "E" or "H" as the answer

#

.

#

""""""
import random


def spinrow():
    symbols = [':cherries:', ':watermelon:', ':lemon:', ':bell:', ':seven:']

    return [random.choice(symbols) for _ in range(3)]


def printrow(row):
    print("─────────────")
    print(f'β”‚{" β”‚ ".join(row)}β”‚')
    print("─────────────")


def get_payout(row, bet):
    if row[0] == row[1] == row[2]:
        if row[0] == ':cherries:':
            return bet * 3
        elif row[0] == ':watermelon:':
            return bet * 4
        elif row[0] == ':lemon:':
            return bet * 5
        elif row[0] == ':bell:':
            return bet * 10
        elif row[0] == ':seven:':
            return bet * 20
    return 0


def main():
    balance = 100

    print("──────────────────────────")
    print("Python Slot'a Hoş Geldin! ")
    print("Semboller: :cherries: :watermelon: :lemon: :bell: :seven:")
    print("──────────────────────────")

    while balance > 0:
        print(f'Kalan bakiye: ${balance}')

        bet = input("Kullanacağınız miktarı giriniz: ")

        if not bet.isdigit():
            print("LΓΌtfen bir sayΔ± giriniz")
            continue

        bet = int(bet)

        if bet > balance:
            print("Yetersiz bakiye")
            continue

        if bet <= 0:
            print("0'dan yΓΌksek bir miktarda para kullanabilirsiniz")
            continue

        balance -= bet

        row = spinrow()
        print("DΓΆnΓΌyor...\n")
        printrow(row)

        payout = get_payout(row, bet)

        if row[0] == row[1] == row[2] == ':seven:':
            print("JACKPOT! :tada:")

        if payout > 0:
            print(f'${payout} KazandΔ±n!')

        else:
            print("Kaybettin!")

        balance += payout

        play_again = input("Tekrar oynamak ister misin? (E/H): ").upper()

        if play_again == 'E':
            continue
        elif play_again == 'H':
            break
        while play_again != 'E' or 'H':
            pass
#

print("───────────────────────────────────────────")
    print(f"Oyun bitti! Son durumdaki bΓΌtΓ§en ${balance}")
    print("───────────────────────────────────────────")


if __name__ == '__main__':
    main()
amber estuary
#

!code

torpid cragBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

amber estuary
#

And you want the loop to wrap the code that you want to repeat.

tiny lily
#

yep

amber estuary
tiny lily
#

I should have the loop before the if right?

#

but even if I do it

#

it still doesnt work

#

I know the code isn't right

#

the last version I left was wrong and I can't fix it

amber estuary
#

By "wrap", I mean that in this code:

while True:
    print(1)

The while True loop is "wrapping" the print call.

tiny lily
#

I got the wrapping but what will I wrap not only wrapping part I didnt get anything about the code part I gave you think me like zero

#

thank you for helping but why did you just answered quarter of my question and disappeared?

tiny lily
torpid cragBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.