Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 3.6 language Function name(7): guess_dumplings Parameters: number of dump

ID: 3883781 • Letter: P

Question

Python 3.6 language

Function name(7): guess_dumplings Parameters: number of dumplings ate (int) Return value: number of guesses the user took (int) Description: Write a function that takes an integer value of the number of dumplings you ate, and asks the user to try to guess this number. When the user guesses the correct value, print a congratulatory statement and tell them how many guesses it took. If the user inputs "quit" (exactly the string quit, don't worry about edge cases like 'QUIT' or 'Quit'), your code should end, and print the correct answer. The integer returned if the user quits should be-1. If the user has not guessed the correct answer within the 5^th try, print that they've lost the game, and return 0. You must use a while-loop. Test Cases: > > > a = guess-dumplings(5) > > > What is your guess?" rightarrow 2 > > > "Wrong answer, try again" rightarrow 4 > > > "Wrong answer, try again" rightarrow 5 > > > "Correct! It took you 3 tries." > > > print (a) > > > 3 > > > a = guess_dumplings(5) > > > "What is your guess?" rightarrow 2 > > > "Wrong answer, try again" rightarrow 4 > > > "Wrong answer, try again" rightarrow quit > > > "The correct answer was 5." > > > print (a) > > > -1 > > > a = guess_ dumplings(5) > > > "What is your guess?"rightarrow 1 > > > "Wrong answer, try again" rightarrow 2 > > > "Wrong answer, try again" rightarrow 3 > > > "Wrong answer, try again" rightarrow 4 > > > "Wrong answer, try again" rightarrow 6 > > > "You lose. The correct answer Was 5. > > > print (a) > > > 0

Explanation / Answer

def guess_dumpling(x): c = 1 n = input("What is your guess ? ") while(1): if n == str(x): print("Correct! It took you %d tries." %c) return c elif n == "Quit" or n == "QUIT" or n == "quit": print("The correct answer was %d " %x) return -1 elif c == 5: print("You lose. The correct answer was %d " %x ) return 0 else: c += 1 n = input("Wrong answer, try again ") d = input("Enter number of dumpling ate ") d = int(d) a = guess_dumpling(d) print(a)