repl.it
@Pythonier/

Worlds Hardest Game

Python

No description

fork
loading
Files
  • main.py
  • winners.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
import random, sys
from time import sleep
from replit import clear
from colors import red,green,cyan

def write(string):
  for char in string:
    sys.stdout.write(char)
    sys.stdout.flush()
    sleep(.05)

clear()
print('Have you played before? y/n')
play = input('')
if play == 'y':
  input('Press enter to continue:')
else:
  write("The goal is to guess a random number between 1 and 2. You will have to do this 10 times to win. If you guess incorrectly you lose. Good Luck!")
  sleep(.5)
playAgain = 'y'
while True:
  i = 1
  guess = '1'
  rand = 1
  while int(guess) == rand and i < 11:
    clear()
    print('Guess ' + str(i))
    print('What is your guess (1 or 2)')
    guess = input('')
    rand = random.randint(1,2)
    sleep(.3)
    print(cyan(rand))
    try: 
      if int(guess) == rand: 
        write(green('Correct!'))
        sleep(.2)
        i += 1
      else:
        write(red('Wrong!'))
        sleep(0.5)
        clear()
        print(red("GAME OVER"))
    except: 
      print(red('Invalid Input! Please choose 1 or 2'))
      guess = rand
      
  if i == 7:
    clear()
    print(green('YOU WIN'))
    print('Would you like to add your name to the list of winners? y/n ')
    save = input('')
    print('What is your username? ')
    username = input('')
    with open('winners.txt', 'a') as f:
      f.write(username + "\n")
    clear()
  sleep(.5)
  playAgain = input('Press Enter To Play Again:')
?