Aug-06-2019, 05:07 PM
(This post was last modified: Aug-06-2019, 05:08 PM by inamullah9.)
I learned basic python in 1 week and here is what i developed. It is a basic rock paper scissor game between user and computer. One who scores 5 points wins the game. It took me 30 minutes to complete this. Here is the code
import random print ('WELCOME TO ROCK PAPER SCISSOR GAME\n\t\tDEVELOPED BY INAMULLAH9\n') cscore=0 pscore=0 def score(): global cscore global pscore global name print (name,'score :',pscore) print ('computer score: ',cscore) print('PLEASE ENTER YOUR NAME') name=input() print(name, 'VS computer') while True: if pscore == 5: print (name,'WIN THE MATCH') input() break elif cscore == 5: print ('Computer WINS THE MATCH') input() break print('Enter\n1 for ROCK \n2 for PAPER \n3 for SCISSOR') x=int(input()) if x <1 or x>3: print('invalid choice\ntry again') continue p=random.randint(1,3) if p==1 and x==1: print ('rock vs rock') if p==2 and x==2: print ('paper vs paper') if p==3 and x==3: print ('scissor vs scissor') if p==1 and x==2: print ('rock vs paper') if p==2 and x==3: print ('paper vs scissor') if p==3 and x==1: print ('scissor vs rock') if p==2 and x==1: print ('paper vs rock') if p==3 and x==2: print ('scissor vs paper') if p==1 and x==3: print ('rock vs scissor') if x==1 and p==1 or x==2 and p==2 or x==3 and p==3: print('DRAW') score() continue elif x==1 and p==3 or x==2 and p == 1 or x==3 and p==2: print(name," Win") pscore+=1 score() continue elif p==1 and x==3 or p==2 and x==1 or p==3 and x==2: print('Computer Win') cscore+=1 score() continue