#๐Ÿ”’ I'm trying to make it so the streak is increment each time the function is replayed and also make

17 messages ยท Page 1 of 1 (latest)

wraith needle
#

so it rolls a new dice each time, what do i do

opaque edgeBOT
#

@wraith needle

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.

wraith needle
#

my bad, for sending the ss small

#

but im unsure on how to make the dice roll each time the function is called again

#

import random

def dice_Rolled(dice_total):
streak = 0

guess = int(input("What do you think is the total score: "))

if guess == dice_total:
    streak = streak + 1 
    print("You were correct")
    print(streak)
    if streak == 6:
        print("You are a member of the knight rose.")


else:
    streak = 0
    print("You got it incorrect!")
    print(streak, "That is now your current streak.")

total = 0
rolled_dice = 0
while rolled_dice < 6:
dice_rolled_in_loop = random.randint(1,6)
print(f"The dice you rolled was, {dice_rolled_in_loop}")
if dice_rolled_in_loop == 3:
total += 2
elif dice_rolled_in_loop == 5:
total += 4
else:
total += 0
rolled_dice += 1
dice_Rolled(total)

play = input("Would you like to play a game: ")
while play.capitalize() == "Yes":
dice_Rolled(total)
play = input("Would you like to play again?")

#

idk how to format

#

but thats the code

snow osprey
opaque edgeBOT
#
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.

snow osprey
#

If streak needs to persist across calls though, I'd return it from the function, then pass it back in on the next call.

#

Or make the function a method on a class, and have the streak as an instance variable.

#

It's resetting every call because you have it as a local variable that gets set to 0 every call.

prisma wigeon
#

you can take the streak variable out of the function and call it as a global variable within the function, this makes it so that each function call doesn't reset it.

streak = 0

def func1():
  global streak
  streak += 1

for x in range(10):
  func1()
snow osprey
#

But try to avoid globals when better options are available.

prisma wigeon
#

you're right

opaque edgeBOT
#
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.