Skip to content

Instantly share code, notes, and snippets.

@AdilAzhari
Created February 13, 2018 18:17
Show Gist options
  • Select an option

  • Save AdilAzhari/1de65f7e9cc9cc527c7e88fc4f7da659 to your computer and use it in GitHub Desktop.

Select an option

Save AdilAzhari/1de65f7e9cc9cc527c7e88fc4f7da659 to your computer and use it in GitHub Desktop.
print("Read The Instruction ")
print("Two players start from 0 and alternatively add a number from 1 to 10 to the sum ")
print("The player who reaches 100 wins.")
print("To Play Against Human Enter 1 ")
print("To Play Against Computer Enter 2 ")
y=int(input("Enter number"))
#To play against human
import random
sum=0
if y==1:
while True :
for i in range (10):
x=int(input("Player 1 enter number :\n"))
if x < 10:
sum+=x
print(sum)
if sum==100:
print("Player 1 win")
print("Game Over")
x=int(input())
break
else:
print("Number Not In Range")
print("Re-enter Number")
continue
for i in range (10):
x=int(input("Player 2 enter number :\n"))
if x < 10:
sum+=x
print(sum)
if sum==100:
print("Player 2 win")
print("Game Over")
x=int(input())
break
else:
print("Number Not In Range")
print("Re-enter Number")
continue
#To play against compiter
if y==2:
while True :
for i in range (10):
x=int(input("Player 1 enter number :\n"))
if x < 10:
sum+=x
print(sum)
if sum==100:
print("Player 1 win")
print("Game Over")
x=int(input())
break
else:
print("Number Not In Range")
print("Re-enter Number")
continue
for i in range (10):
x=random.randint(1,9)
print("Computer Entered ",x)
if x < 10:
sum+=x
print(sum)
if sum==100:
print("Computer win")
print("Game Over")
x=int(input())
break
else:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment