-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
46 lines (40 loc) · 1.4 KB
/
game.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
# Simple random number guessing game by "The Pulsar (001pulsar)"
# modules section
import os # for clearing the screen
import sys # to exit the program
import random # to guess random number
# game function
def game():
rangeStart = int(input("Number from: "))
rangeEnd = int(input("Number to: "))
chosenNumber = random.randrange(rangeStart, rangeEnd)
guessedNumber = int(input("Enter your guess: "))
if (guessedNumber == chosenNumber):
print(f"Correct guess!\nNumber: {chosenNumber}\nGuess: {guessedNumber}")
print("\n\nPress enter to go back to main menu..")
input()
mainMenu()
else:
print(f"Wrong guess!\nNumber: {chosenNumber}\nGuess: {guessedNumber}")
print("\n\nPress enter to go back to main menu..")
input()
mainMenu()
# main menu function
# this function would get called upon executing the program
def mainMenu():
os.system('clear')
print("...Number guessing game...")
print("Enter (1) to start\nEnter (2) to exit")
mainMenuChoice = int(input())
# not for dev:
# update the main menu choice codes so that the choice will be taken automatically upon typing without the need to press enter
# okie dokie
if (mainMenuChoice == 1):
game()
elif (mainMenuChoice == 2):
sys.exit()
else:
print("Invalid choice")
input()
mainMenu()
mainMenu()