Nov-08-2017, 07:30 PM
I'm very new to coding. I'm building a number guessing game. I had it working as a while loop, but I'm learning to define functions. I've built this, and I can make the results work if I have the resulting success or failure just print within my defined function, but I want it to return values outside of my defined function so I can act with the out there.
import random import pygame import sys from pygame.locals import * def game (theNumber, newNumber): try: int(newNumber) except: print("That's not going to work. I need a number from 0 to 10.") return myNumber = int(newNumber) if myNumber >= 11 or myNumber < 0: print("I said 0 to 10. Let's try again:") return elif theNumber == myNumber: return True, theNumber else: return False, theNumber doYou = input("Would you like to play? ") if doYou == "Yes": theNumber = random.randrange(0,10) newNumber = input("Guess a number from 0 to 10.") game(theNumber, newNumber) else: print("Consent is vital, I need a clear answer: Yes") if game(theNumber, newNumber) == True: print("Nope, the answer was", theNumber) elif game(theNumber, newNumber) == False: print("Congratulations, you guessed it: ", theNumber)I know I have unnecessary imports at the top, but I want to be able to act with the returns from my game function.