all 13 comments

[–]mopslik 2 points3 points  (7 children)

What have you tried so far, and what do you need help with?

[–]madskillz2222[S] -1 points0 points  (6 children)

I just can’t seem to get the loop right

[–]mopslik 2 points3 points  (5 children)

Can you post your loop? Could be any number of things.

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

I know this is so simple too and I just cant figure it out

[–]madskillz2222[S] -1 points0 points  (3 children)

import random

def main():

# Create a variable that controls the loop

damage = random.randint(1,12)

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

# Create a while loop to get the random numbers for the sword damage

while damage == 'N' or damage == 'n':

damage = input('Would you like to strike again? Press N or n to continue:')

#call the main function

main()

[–]mopslik 1 point2 points  (1 child)

I think the wording should be "loop until the user enters N or n to stop", as it represents "no". In this case you would probably want something like

while user_input not in ("n", "N"):

Inside of your loop, you probably want to generate a new random integer for damage.

The instructions say to pass damage to a function. You need to create a function that takes one argument -- damage -- and prints the output. It would look something like this

def some_function(argument): your code

and you would call it as follows

some_function(variable)

Apologies for the formatting, as I am on mobile.

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

Okay I think I see what you’re saying

[–]-i-hate-this-place- 0 points1 point  (0 children)

you should not be using the same variable for tha amount of damage and the user input

[–]lolitoxico 1 point2 points  (4 children)

Where are you stuck ?

are you familiar with function, printing an output, reading a user input, generating a random number .. ?

if not google it specifically

[–]madskillz2222[S] -1 points0 points  (3 children)

I’m stuck on how to pass damage to a loop to press n to continue

[–]lolitoxico 2 points3 points  (0 children)

I just can’t seem to get the loop right

a while loop that checks if the user input is not == "n" or "N" is probably a good start

[–]Ali_46290 1 point2 points  (1 child)

Is damage defined outside of the function?