Computer Science, asked by eesaprasad27, 1 month ago

Can you work out what this function does? Try passing different parameters to the attempts function to see what it does.

def attempts(n):

x = 1

while x <= n:

print("Attempt " + str(x))

x += 1

print("Done")


attempts(5)

Answers

Answered by Anonymous
15

[The given còde is written in python.]

Correct còde would be :-

def attempts(n):

‎ ‎ ‎x = 1

‎ ‎ ‎while x <= n:

‎ ‎ ‎print("Attempt " + str(x))

‎ ‎ ‎x += 1

‎ ‎ ‎print("Done")

attempts(5)

Explanation :-

Output of the given còde will be :

Attempt 1

Attempt 2

Attempt 3

Attempt 4

Attempt 5

Done

The given function will take an argument, there is a variable named x holding the value 1, which ìncrements by 1 every step, with the help of while loop. This loop continues till the value of x will be equal to the argument entered in the function. The function will print the value from 1 to the argument value as a string along with the word "Attempt" untill the value of x and argument become equal. At last the program will print "Done".

[ There were some ìndentation érrors in your còde, I have corrected them for the program to run safely without throwing an érror. I have entered some white spaces in the còde to shòw correct ìndentation, don't còpy and pàste this program as blank spaces are not allowed in còde.]

Similar questions