gamee

Python code posted by avi
created at 20 Jan 13:51

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
print("Code to play games 'cut and o' or 'stone paper and scissors")
print("press 4 to play 'cut and o' or 5 to play 'stone paper and scissors")
opt=int(input('Enter the game numberr you want ot play:'))
if opt==4:
    print('You have decided to play "cut and o"')
    p=0
    print("""Press 'A' if you want to play with a player else press 'Z' in
    to play with computer""")
    inp=input('Enter the option to be seleected:')
    n1=input("Enter The Name Of The 1st Player :")
    n2=input("Enter The Name Of The 2nd Player :")
    print("Choose The Character For",n1,"\nPress 1 For X and press 2 for O :")
    ch=int(input())
    if ch==1:
        p1="X"
        p2="O"
    else:
        p1="O"
        p2="X"
    print(n1,"Will Play With",p1,"\n",n2,"Will Play With",p2,"\n\n\n")
    aa="\t1\t2\t3"#coordinate of blanks
    print(aa)
    a=list("\n\n1\t_\t_\t_\n\n\n2\t_\t_\t_\n\n\n3\t_\t_\t_")#/n and /t are single elements
    d={(1,1):4,(2,1):6,(3,1):8,(1,2):14,(2,2):16,
       (3,2):18,(1,3):24,(2,3):26,(3,3):28}
    for i in a:
        print(i,end="")
    print("\n\n\nFill The Box By Choosing The Correct set Of Coordinates")
    for i in range(10):
        print("\n\nTurn Of",n1,)
        x=int(input("Enter The x coordinate (1,2,3) :"))
        y=int(input("Enter The Y coordinate (1,2,3) :"))
        a[d[(x,y)]]=p1
        p=p+1
        print(aa)
        for i in a:
            print(i,end="")
        print("\n\nTurn Of",n2,)
        if a[4]==a[6]==a[8]==p1 or a[14]==a[16]==a[18]==p1 or a[24]==a[26]==a[28]==p1 or a[4]==a[14]==a[24]==p1 or a[6]==a[16]==a[26]==p1 or a[8]==a[18]==a[28]==p1 or a[4]==a[16]==a[28]==p1 or a[8]==a[16]==a[24]==p1:
            if p%2==1:
                print(n1,"\n\nHas Won The Game Congratulations !!!!")
            break
        x=int(input("Enter The x coordinate (1,2,3) :"))
        y=int(input("Enter The Y coordinate (1,2,3) :"))
        a[d[(x,y)]]=p2
        p=p+1
        print(aa)
        for i in a:
            print(i,end="")
        if a[4]==a[6]==a[8]==p2 or a[14]==a[16]==a[18]==p2 or a[24]==a[26]==a[28]==p2 or a[4]==a[14]==a[24]==p2 or a[6]==a[16]==a[26]==p2 or a[8]==a[18]==a[28]==p2 or a[4]==a[16]==a[28]==p2 or a[8]==a[16]==a[24]==p2:
            if p%2==0:
                print(n2,"\n\nHas Won The Game Congratulations !!!!")
            break

#code to play stone paper and scissors
elif opt==5:
    #code
    print('''The code is for stone paper scissors game if u give same as the player 2
    then the game will continue and all rules of the game''')
    tup='STONE','PAPER','SCISSORS'
    while True:
        import random as r
        player2=r.randint(0,2)
        option2=tup[player2]
        option1=input("Enter the option:")
        if option1.upper() not in tup:
            print("The value is not defined")
            break
        else:
            print("Value entered from player 2:",option2)
            if option1.upper()=="ROCK" and option2 == 'SCISSORS':
                print("You won !")
                break
            elif option1.upper()=="PAPER" and option2=='STONE':
                print("You won !")
                break
            elif option1.upper()=="SCISSORS" and option2=='PAPER':
                print("You won !")
                break

3.26 KB in 6 ms with coderay