0

Can you use a function Output as an Input in a different function

So, I was wondering if there was a way I could take the output of the bottom two functions to replace the x and y inside number_checker(x,y) whenever I call on it. def number_checker(x,y): if x == y: print("Answer: Correct.\n") if x < y: print("Answer: Incorrect. Guess Lower.\n") if x > y: print("Answer: Incorrect. Guess Higher.\n") def random_digit(): import random random.randint(0, 9) def guess_digit(): print(input("Enter a digit: \n"))

4th Apr 2018, 9:16 PM
Awizal
Awizal - avatar
4 Answers
+ 1
Have you tried? Always try. And the answer is yes. You just have to put their outputs in variables and use those variables as arguments when calling the first... And I would advice putting import random outside the function... Happy coding!!! â˜ș
4th Apr 2018, 9:29 PM
cyk
cyk - avatar
+ 1
Thanks for the help guys, I'm new to programming so this helped me a lot.
5th Apr 2018, 12:26 PM
Awizal
Awizal - avatar
0
return function is the way to go import random def random_digit(): y = random.randint(0, 9) return y this = random_digit() Answer = False while not Answer: def number_checker(x, y): global Answer if x == y: print("Answer: Correct.\n") Answer = True if x < y: print("Answer: Incorrect. Guess Higher.\n") if x > y: print("Answer: Incorrect. Guess Lower.\n") def guess_digit(): y = this x = int(input("Enter a digit:")) return number_checker(x, y) guess_digit()
4th Apr 2018, 9:41 PM
Markus Kaleton
Markus Kaleton - avatar
- 1
def number_checker(x, y): if x == y: print("OK\n") return 1 if x > y: print(">") return 0 if x < y: print("<") return 0 def guess_digit(): return input("Enter a digit: ") def random_digit(): import random return random.randint(0, 9) rand = random_digit() print rand while 1: if number_checker(guess_digit(), rand): break
4th Apr 2018, 9:31 PM
Bartosz Pieszko
Bartosz Pieszko - avatar