Skip to content

Commit 24eac05

Browse files
Matthew HolmesMatthew Holmes
authored andcommitted
adding lab_5
1 parent b7a92ef commit 24eac05

File tree

6 files changed

+156
-0
lines changed

6 files changed

+156
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
from flask import Flask, render_template, request
3+
import random
4+
5+
app= Flask(__name__)
6+
7+
@app.route('/')
8+
def index():
9+
return render_template('index.html')
10+
11+
@app.route('/play_game', methods=['POST'])
12+
def play_game():
13+
result = request.form
14+
15+
user = result['rps']
16+
computer = random.choice(['rock','paper','scissors'])
17+
18+
if user == computer:
19+
message = "It is a tie!"
20+
elif user == 'rock':
21+
if computer == 'scissors':
22+
message = 'You win'
23+
else:
24+
message = 'Computer Wins'
25+
elif user == 'paper':
26+
if computer == 'rock':
27+
message = 'You win'
28+
else:
29+
message = 'Computer wins'
30+
else:
31+
if computer == 'paper':
32+
message= 'you win'
33+
else:
34+
message = 'Computer wins'
35+
36+
print(user,computer, message)
37+
return render_template('results.html', user=user, computer=computer, message=message)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Rock Paper Scissors</title>
8+
</head>
9+
<body>
10+
<h1>Rock Paper Scissors</h1>
11+
<form action="/play_game" method="post">
12+
13+
<label for="rock">Rock</label>
14+
<input type="radio" name="rps" id="rock" value="rock">
15+
16+
<label for="paper">Paper</label>
17+
<input type="radio" name="rps" id="paper" value="paper">
18+
19+
<label for="Scissors">Scissors</label>
20+
<input type="radio" name="rps" id="Scissors" value="scissors">
21+
22+
<button type="submit">Shoot</button>
23+
</form>
24+
</body>
25+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>{{ message }}</title>
8+
</head>
9+
<body>
10+
<h1>Results</h1>
11+
<h3>you chose {{user}}</h3>
12+
<h3>Computer chose {{computer}}</h3>
13+
<h3>{{message}}</h3>
14+
<a href="/">Play again?</a>
15+
</body>
16+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
from flask import Flask, render_template, request
3+
import random
4+
5+
app= Flask(__name__)
6+
7+
@app.route('/')
8+
def index():
9+
return render_template('index.html')
10+
11+
@app.route('/play_game', methods=['POST'])
12+
def play_game():
13+
result = request.form
14+
15+
user = result['rps']
16+
computer = random.choice(['rock','paper','scissors'])
17+
18+
if user == computer:
19+
message = "It is a tie!"
20+
elif user == 'rock':
21+
if computer == 'scissors':
22+
message = 'You win'
23+
else:
24+
message = 'Computer Wins'
25+
elif user == 'paper':
26+
if computer == 'rock':
27+
message = 'You win'
28+
else:
29+
message = 'Computer wins'
30+
else:
31+
if computer == 'paper':
32+
message= 'you win'
33+
else:
34+
message = 'Computer wins'
35+
36+
print(user,computer, message)
37+
return render_template('results.html', user=user, computer=computer, message=message)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Rock Paper Scissors</title>
8+
</head>
9+
<body>
10+
<h1>Rock Paper Scissors</h1>
11+
<form action="/play_game" method="post">
12+
13+
<label for="rock">Rock</label>
14+
<input type="radio" name="rps" id="rock" value="rock">
15+
16+
<label for="paper">Paper</label>
17+
<input type="radio" name="rps" id="paper" value="paper">
18+
19+
<label for="Scissors">Scissors</label>
20+
<input type="radio" name="rps" id="Scissors" value="scissors">
21+
22+
<button type="submit">Shoot</button>
23+
</form>
24+
</body>
25+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>{{ message }}</title>
8+
</head>
9+
<body>
10+
<h1>Results</h1>
11+
<h3>you chose {{user}}</h3>
12+
<h3>Computer chose {{computer}}</h3>
13+
<h3>{{message}}</h3>
14+
<a href="/">Play again?</a>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)