-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
97 lines (72 loc) · 2.15 KB
/
main.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""This file is a number guessing game that is slowly being made."""
# Title: iter4
# Creater: Caleb Young
# Current iteration: 4
# StartDate: 30/5/23
# FinishDate:
# Description: This is a file that is apart of a
# Description p2: set of files that will in the end
# Descriptin p3: hopefullly contain a lovley polished game that works well.
# stuff to be imported
import random
# Variables
randintend = 20
attempt = 4
# welcome
print("Welcome to the random number guessing game.")
print(f"This is a game where you guess a number between the value of 0 and {randintend}.")
# game engine and attempts
def gameengineandlives():
"""Return lives left and run game engine."""
user_input = ""
global attempt
a = random.randint(0, randintend + 1)
for i in range(attempt + 1):
try:
user_input = int(input("Enter Number: "))
except ValueError:
print("Invaild input. Please input a number")
if user_input == (a):
print('You won')
attempt = 0
break
elif user_input >= (a):
print(f"Lower than {user_input}")
print(f'Try again! {attempt} attempts left.')
attempt -= 1
elif user_input <= (a):
print(f"Higher than {user_input}.")
print(f'Try again! {attempt} attempts left.')
attempt -= 1
else:
print('Invalid input, please try again.')
continue
# replay loop
replayloop = True
def replaysys():
"""Replay loop return yes or no info."""
global replayloop
print("Would you like to play again?")
replay_input = input("Y,N ").lower()
if replay_input == "y":
print("Let's play again")
replayloop = True
gameengineandlives()
elif replay_input == "n":
print("Goodbye")
replayloop = False
else:
print("Please input Y or N")
replayloop = True
replaysys()
# Please run well
def plsrun():
"""Do a run command to run the game."""
global attempt
attempt = 4
gameengineandlives()
replaysys()
plsrun()
# replayloop
while replayloop:
plsrun()