adding condition of a subprogram in a different subprogram? python -
im beginner in python , ive been coding piece 2 players asked reach number (25 in case) , asked alternate between 2 players. ive put player in different subprogram , im alternating in different subprogram. ive tried many ways none seem work.
def get_input_from_player(player): ''' same get_input, except time, prompt includes player supposed supply input. :param player: player, either 1 or 2 :return: integer, either 1,2 or 3 ''' ''' same in d(), time, make sure user can't enter number put total on 25. :return: none ''' = true total = 0 while a: ask_user = input ("player " + str(player) +" enter number (1, 2 or 3):") if ask_user == 1 or ask_user == 2 or ask_user == 3: print "valid input" total = ask_user + total if total < 25: print total else: = false else: print "invalid input" print "----------------xxxxxxxxxxxxxxxxxxxxxx---------------------" pass # replace code def f(): ''' same in e(), ths time, print out players move is, on each turn. there 2 players, player 1 starts , alternate. hint: add player variable, use get_input_from_player(player) :return: none = true total = 0 team1 = 1 team2 = 2 **''' playerone = get_input_from_player(1) playertwo= get_input_from_player(2)** #here have trouble because should alternate 1 of players in invalid print "----------------xxxxxxxxxxxxxxxxxxxxxx---------------------" pass # replace code # remove # in front of function below call ''' a() b1(0) b1(-5) b1(15) b2(0) b2(-5) b2(15) get_input() c() d() e() ''' #get_input_from_player(1) #get_input_from_player(2) f() #raceto25() #raceto(25) #raceto(17) #raceto(100)
this looks suspiciously homework assignment.
i tried understand functionality looking for, may have missed something. solution improved upon, didn't want change arguments or return values of functions.
in general should avoid using non descriptive names f , a.
total = 0 def get_input_from_player(player): while true: ask_user = input("player " + str(player) + " enter number (1, 2 or 3):") if ask_user == 1 or ask_user == 2 or ask_user == 3: if 25 < ask_user + total: continue else: return ask_user else: print "invalid input" def who_is_first_to_25(): global total while true: playerone = get_input_from_player(1) total += playerone if 25 <= total: print "player 1 first 25" break playertwo = get_input_from_player(2) total += playertwo if 25 <= total: print "player 2 first 25" break total = 0 print "----------------xxxxxxxxxxxxxxxxxxxxxx---------------------" who_is_first_to_25()
Comments
Post a Comment