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() 

  1. userinput() calls function "userinput", discard result. same remark applies computerinput().

  2. userinput == 1 asks whether function userinput equal 1. isn't. same remark applies computerinput == 3 , others.

  3. in function "userinput", userinput = ... binds name "userinput" result of expression. makes "userinput" local variable of function. function doesn't explcitly return anything, therefore returns none.

  4. if you're using python 3, input returns string, , should convert result int. if you're using python 2, input evaluates whatever entered, isn't safe; should use raw_input instead , convert result int.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -