0

Python functions

I am trying to write a function that generates a tuple of 2 + single digit integers, and another function that takes the result of this function and multiplies them, and checks wjether the input entered by the user matches the multiplication result if not display incorrect. Now the tuple generation function works but im not sure wjy the secod function is unable to multiple the results of previous function https://code.sololearn.com/cys12mmFut63/?ref=app

5th Apr 2022, 8:31 AM
Reynolds Onyango
Reynolds Onyango - avatar
3 Answers
0
#you are comparing different tuple. Each time call to generate will return different tuple.. #result[i] * i returns num*index import random def generate(): haha = list() for i in range (0,2): haha.append(random.randrange(1,10,1)) tuple_val = tuple(haha) return tuple_val def test(n): result = generate() #use same tuple for comparing.. print("Find the multiplication of", result) j=1 for i in range(len(result)): j =j*result[i] if n == j: print(" Correct answer") else: print("your answer", n,"!=",j,"try again") return result print(" Enter your result below\n") x = int(input()) test(x) #hope it helps..
5th Apr 2022, 9:27 AM
Jayakrishna 🇼🇳
0
It works but only reveals the numbers to be multiplied to the user after multiplication has taken place. How can i present this numbers to the user before the multiplication is done
5th Apr 2022, 10:11 AM
Reynolds Onyango
Reynolds Onyango - avatar
0
Means how? print result tuple Multiplication : j Correct or Wrong? Like this? If yes, print j value after for loop before if block. if not, how..? but just try, to interchange output statements...
5th Apr 2022, 11:57 AM
Jayakrishna 🇼🇳