SHARE
TWEET

Untitled

a guest Aug 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. def getRandomNumber():
  4.     randomNumber=random.randint(1,3)
  5.     return randomNumber
  6.  
  7. def getCompChoice(randomNumber):
  8.  
  9.     if randomNumber==1:
  10.         compChoice='rock'
  11.     elif randomNumber==2:
  12.         compChoice='paper'
  13.     else:
  14.         compChoice='scissors'
  15.     return compChoice
  16.  
  17.  
  18.  
  19.  
  20. def getUserChoice():
  21.     userChoice=input('Enter your choice: ')
  22.     return userChoice
  23.  
  24. def compare(compChoice,userChoice):
  25.  
  26.  
  27.     rockmsg='rock smashes scissors'
  28.     scissorsmsg='scissors cut paper'
  29.     papermsg='paper wraps rock'
  30.     winner='no winner'
  31.     message=''
  32.  
  33.     if compChoice=='rock' and userChoice=='scissors':
  34.         winner='the Computer won'
  35.         message=rockmsg
  36.  
  37.     elif compChoice=='scissors' and userChoice=='rock':
  38.         winner='You won'
  39.         message=rockmsg
  40.  
  41.     if compChoice=='scissors' and userChoice=='paper':
  42.         winner='the Computer won'
  43.         message=scissorsmsg
  44.  
  45.     elif compChoice=='paper' and userChoice=='scissors':
  46.         winner='You won'
  47.         message=scissorsmsg
  48.  
  49.     if compChoice=='paper' and userChoice=='rock':
  50.         winner='the Computer won'
  51.         message=papermsg
  52.  
  53.  
  54.     elif compChoice=='rock' and userChoice=='paper':
  55.         winner='You won'
  56.         message=papermsg
  57.  
  58.     return winner, message
  59.  
  60.  
  61.  
  62. def main():
  63.  
  64.  
  65.     winner='no winner'
  66.  
  67.     while winner=='no winner':
  68.         random_number=getRandomNumber()
  69.         comp_choice=getCompChoice(random_number)
  70.         user_choice=getUserChoice()
  71.         print('The choice of the computer is',comp_choice)
  72.         winner,message=compare(comp_choice,user_choice)
  73.  
  74.  
  75.         if winner=='no winner':
  76.  
  77.             print(winner)
  78.             print('You both chose the same thing. the game will start again..')
  79.  
  80.  
  81.         if winner!='no winner':
  82.             print(winner,',',message,sep='')
  83.  
  84.  
  85. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top