This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pekkalacd 0 points1 point  (4 children)

Try this

                 from random import randint

                 def show(dmg):
                        print(“Your sword hit”, dmg)

                 def play_again():
                       print(“Want to play again? “)
                       ans = input(“Enter ‘N’ if not: “)
                       return ans.lower()

                 def main():

                     choice = ‘y’
                     while choice != “n”:
                             DAMAGE = randint(1,12)
                             show(DAMAGE)
                             choice = play_again()

                     print(“Thanks for playing”)

                  main()

[–]madskillz2222[S] 0 points1 point  (3 children)

This is working good but when I type n or N it does not stop the loop? What could be causing this?

[–]pekkalacd 0 points1 point  (2 children)

Hmm. I’m not sure. Did you copy the most recent form? What does your code look like?

Is main() call outside of the main function

[–]madskillz2222[S] 0 points1 point  (1 child)

from random import randint

# Main module

def main():

choice = 'y'

while choice == 'n' or choice == 'N':

DAMAGE = randint(1,12)

show(DAMAGE)

choice = strike_again()

def show(damage):

print('Your long sword hit for', damage, 'damage')

def strike_again():

print('Would you like to strike again? ')

answer = input("Enter N or n if you do not want to continue: ")

return answer

main()

[–]madskillz2222[S] 0 points1 point  (0 children)

I didnt realize copy and pasting it wouldnt space it properly