Last active
March 22, 2016 13:41
-
-
Save nauman-chaudhary/0409f6a9a6e5292405e1 to your computer and use it in GitHub Desktop.
Assignment 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print ('Simple Calculator by BSE14M503') | |
print ('1.Addition') | |
print ('2.Subtraction') | |
print ('3.Multiplication') | |
print ('4.DIvision') | |
print ('5.Moduluds') | |
op = int(input('Choose Operation: ')) | |
first = int(input('Enter first operand: ')) | |
second = int(input('Enter sencond operand: ')) | |
if op == 1: | |
print ('Answer:',first+second) | |
elif op == 2: | |
print ('Answer:',first-second) | |
elif op == 3: | |
print ('Answer:',first*second) | |
elif op == 4: | |
print ('Answer:',first/second) | |
elif op == 5: | |
print ('Answer:',first%second) | |
input('Press enter to quit') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def cls(): | |
os.system('cls' if os.name=='nt' else 'clear') | |
print ('Simple Tic Tac Toe') | |
check = True | |
val = ['0','1','2','3','4','5','6','7','8','9'] | |
t = 1 | |
p = 0 | |
sign = ' ' | |
print(' {0} | {1} | {2} '.format(val[1],val[2],val[3])) | |
print ('_'*5 + '|' + '_'*5 + '|'+'_'*5) | |
print(' {0} | {1} | {2} '.format(val[4],val[5],val[6])) | |
print ('_'*5 + '|' + '_'*5 + '|'+'_'*5) | |
print(' {0} | {1} | {2} '.format(val[7],val[8],val[9])) | |
print (' '*5 + '|' + ' '*5 + '|'+' '*5) | |
while check: | |
if t%2==0: | |
p1 = int(input('''Player 2's turn [X]: ''')) | |
sign = 'X' | |
p = 2 | |
else: | |
p1 = int(input('''Player 1's turn [O]: ''')) | |
sign = 'O' | |
p = 1 | |
if (p1>0 and p1<10): | |
t+=1 | |
if (p1 == 1 and val[1] == '1'): | |
val[1] = sign | |
elif (p1 == 2 and val[2] == '2'): | |
val[2] = sign | |
elif (p1 == 3 and val[3] == '3'): | |
val[3] = sign | |
elif (p1 == 4 and val[4] == '4'): | |
val[4] = sign | |
elif (p1 == 5 and val[5] == '5'): | |
val[5] = sign | |
elif (p1 == 6 and val[6] == '6'): | |
val[6] = sign | |
elif (p1 == 7 and val[7] == '7'): | |
val[7] = sign | |
elif (p1 == 8 and val[8] == '8'): | |
val[8] = sign | |
elif (p1 == 9 and val[9] == '9'): | |
val[9] = sign | |
else: | |
t-=1 | |
cls() | |
print(' {0} | {1} | {2} '.format(val[1],val[2],val[3])) | |
print ('_'*5 + '|' + '_'*5 + '|'+'_'*5) | |
print(' {0} | {1} | {2} '.format(val[4],val[5],val[6])) | |
print ('_'*5 + '|' + '_'*5 + '|'+'_'*5) | |
print(' {0} | {1} | {2} '.format(val[7],val[8],val[9])) | |
print (' '*5 + '|' + ' '*5 + '|'+' '*5) | |
if (val[1] == val[2] == val[3]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[4] == val[5] == val[6]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[7] == val[8] == val[9]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[1] == val[4] == val[7]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[2] == val[5] == val[8]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[3] == val[6] == val[9]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[1] == val[5] == val[9]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[3] == val[5] == val[7]): | |
print ('Player {} wins!'.format(p)) | |
check = False | |
elif (val[1]!='1' and val[2]!='2'and val[2]!='3'and val[2]!='4'and val[2]!='5'and val[2]!='6'and val[2]!='7'and val[2]!='8'and val[2]!='9') : | |
print ('Draw!') | |
check = False | |
input('Press enter key to exit') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment