repl.it
@Pythonier/

Higher Lower Game

Python

The goal is to guess the number between 1 and a set value in as few guesses possible.

fork
loading
Files
  • main.py
  • scores.txt
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
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
import random, time, replit, sys
from colors import red,green,blue,magenta

def clear():
  replit.clear()

def type(string):
  for char in string:
    sys.stdout.write(char)
    sys.stdout.flush()
    time.sleep(0.08)

clear()

start = input("Have you played before? y/n  ")

if start == "y":
  input("Press enter to begin: ")
else:
  clear()
  type("This is a simple Higher Lower Game. There will be a random number generated from 1 to choice. After you make your guess, the computer will tell you if the mistery number is higher or lower than your guess.")
  input("\nPress enter to begin: ")
clear()
s = input("What would you like to set the maxiumum value to: ")
while s == int:
  print(red("Please choose a number above 0!")) 
s = int(s)
while not s > 0:
  print(red("Please choose a number above 0!")) 
r = random.randint(1,s)
guess = 0
i = 0
clear()
while not guess == r:
  i += 1
  try: 
    guess = int(input(blue("Guess " + str(i) +   ": ")))
  except: 
    print(red('Invalid Input!'))
    clear()
    i -= 1

  if guess > r:
    type(red("Lower"))
    clear()
  elif guess < r:
    type(green("Higher"))
  elif guess == r:
    type(green("You got it!"))
  time.sleep(1)
  clear()
guesses = str(i)
type("Nice job, you did it in " + green(guesses) + " guesses!\n")
time.sleep(.2)
type('Would you like save your score? y/n')
saveScore = input("\n")
if saveScore == 'y':
  clear()
  type("What is your username?")
  username = input("\n")
  with open('scores.txt', 'a') as f:
    f.write(username + ": " + str(s)+': ' +guesses+"\n")
  time.sleep(.2)
  clear()
  print('Saving')
  time.sleep(.5)
  clear()
  print('Saving.')
  clear()
  time.sleep(.5)
  print('Saving..')
  time.sleep(.5)
  clear()
  print('Saving...')
  time.sleep(0.5)
  clear()
  print(green('SAVED'))


?