0

use of input() in my own function

How do I use input in my own function? for example: >>> def f_input(): >>> player1=input("Player 1 choose \n") >>> player2=input("player 2 choose \n") How can i call 'player1' and 'player2' outside of the function?

23rd Sep 2019, 7:03 AM
Dionisios Papadimitriou
Dionisios Papadimitriou - avatar
3 Respostas
+ 2
thanks both of you... really helpful!!!
23rd Sep 2019, 9:11 AM
Dionisios Papadimitriou
Dionisios Papadimitriou - avatar
+ 1
You can wrap them (player1 and player2) in a tuple and return it. Then f_input caller can use it. def f_input(): player1 = input("Player 1") player2 = input("Player 2") return (player1, player2) # main players = f_input() print(players, type(players))
23rd Sep 2019, 8:38 AM
Ipang