#π problem about loops and if statements
32 messages Β· Page 1 of 1 (latest)
@tiny lily
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.
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()
!code
And you want the loop to wrap the code that you want to repeat.
yep
I meant that as a statement. If you want a loop to repeat code, the loop should wrap the code to repeat. You have the loop after the if.
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
By "wrap", I mean that in this code:
while True:
print(1)
The while True loop is "wrapping" the print call.
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?
if u came again to answer please give me the right code beside explaining (Im understanding it easier when I compare the wrong and the correct one)
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.