python - elif statement returning the "lost" result each time incorrectly. (homework) -
i have updated code changes made. still getting incorrect results...
# import statements import random # define main function ask input, generate computer choice, # determine winner , show output when finished. def main(): # initialize accumulators tie = 0 win = 0 lose = 0 score = 0 # initialize variables user = 0 computer = 0 # initialize loop control variable again = 'y' while again == 'y': userinput() computerinput() if score == win: print('you won round, job!') win += 1 elif score == tie: print('you tied round, please try again!') tie += 1 else: print('you lost round, please try again!') lose += 1 again = input('would play round (y/n)? ') #determine winning average average = (win / (win + lose + tie)) print('you won ', win, 'games against computer!') print('you lost ', lose, 'games against computer.') print('you tied computer for', tie) print('your winning average is', average) print('thanks playing!!') # user input calculation def userinput(): print('welcome rock, paper, scissor!') print('please make selection , and luck!') print('1) rock') print('2) paper') print('3) scissor') user = int(input('please enter selection here: ')) print('you selected', user) # compter input calculation def computerinput(): computer = random.randint(1, 3) print('the computer chose', computer) def getscore(): if user == 1 , computer == 3: score = win return score elif user == 2 , computer == 1: score = win return score elif user == 3 , computer == 2: score = win return score elif user == computer: score = tie return score else: score = lose return score # call main main()
userinput()calls function "userinput", discard result. same remark appliescomputerinput().userinput == 1asks whether functionuserinputequal 1. isn't. same remark appliescomputerinput == 3, others.in function "userinput",
userinput = ...binds name "userinput" result of expression. makes "userinput" local variable of function. function doesn't explcitly return anything, therefore returnsnone.if you're using python 3,
inputreturns string, , should convert result int. if you're using python 2,inputevaluates whatever entered, isn't safe; should useraw_inputinstead , convert result int.
Comments
Post a Comment