@TheFlooBearer/

Python Guessing Game Exercise

Python

Just a test of the random variable.

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.26157773816752883","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJhbmRvbQppbXBvcnQgbWF0aAppbXBvcnQgdGltZQoKCm51bWJlciA9IHJhbmRvbS5yYW5kaW50KDEsIDEwKQpudW1iZXIxID0gc3RyKG51bWJlcikKdHJpZXMgPSAzCnRyaWVzMSA9IHN0cih0cmllcykKCgp1bmFtZSA9IGlucHV0KCJIZWxsbywgd2hhdCBpcyB5b3VyIHVzZXJuYW1lPyBcbiIpCgpwcmludCAoIkhlbGxvLCAiICt1bmFtZSsgIi4iICwpCgplbnRlcj0gaW5wdXQoIldvdWxkIHlvdSBsaWtlIHRvIHBsYXkgdGhpcyBnYW1lIChHdWVzcyB0aGUgbnVtYmVyKT8gKFkgZm9yIHllcywgTiBmb3Igbm8uKVxuIikKCgoKaWYgZW50ZXIgPT0gIlkiOgogICAgcHJpbnQgKCJXZWxjb21lIHRoZW4sIGxldCB1cyBiZWdpbi4iKQogICAgdGltZS5zbGVlcCgxKQogICAgZ3Vlc3MgPSBpbnB1dCgiRW50ZXIgeW91ciBudW1iZXIsIHBpY2sgd2lzZWx5LCBvdXQgb2YgdGVuLlxuIikKCgogICAgaWYgaW50KGd1ZXNzKSA9PSBudW1iZXI6CiAgICAgICAgcHJpbnQgKCJDb25ncmF0cyEgWW91IHdvbiEgdGhlIG51bWJlciB3YXMgIitudW1iZXIxKyIuIENvbWUgYWdhaW4hIikKICAgICAgICB0aW1lLnNsZWVwKDUpCiAgICBpZiBpbnQoZ3Vlc3MpIT0gbnVtYmVyIGFuZCB0cmllcz49MToKICAgICAgICBwcmludCAoIlxuIFRyaWVzIGxlZnQ6IitzdHIodHJpZXMpKQogICAgICAgIGd1ZXNzPSBpbnB1dCgiQWdoISBTbyBjbG9zZS4gVHJ5IGFnYWluIFxuIikKICAgICAgICB0cmllczogaW50ID0gdHJpZXMgLSAxCgoKICAgICAgICBpZiBpbnQoZ3Vlc3MpID09IG51bWJlcjoKICAgICAgICAgICAgcHJpbnQgKCJDb25ncmF0cyEgWW91IGhhdmUgd29uISBcbiIsICJZb3VyIHNjb3JlIGlzICIrdHJpZXMxICsiLiBSZXJ1biB0aGUgcHJvZ3JhbSB0byBkbyBpdCBhZ2FpbiEiKQogICAgICAgICAgICB0aW1lLnNsZWVwKDUpCiAgICAgICAgaWYgaW50KGd1ZXNzKSAhPSBudW1iZXIgYW5kIHRyaWVzID49IDE6CiAgICAgICAgICAgIHByaW50KCJcbiBUcmllcyBsZWZ0OiIgKyBzdHIodHJpZXMpKQogICAgICAgICAgICBndWVzcyA9IGlucHV0KCJBZ2ghIFNvIGNsb3NlLiBUcnkgYWdhaW5cbiIpCiAgICAgICAgICAgIHRyaWVzOiBpbnQgPSAodHJpZXMgLSAxKQoKCiAgICAgICAgICAgIGlmIGludChndWVzcykgPT0gbnVtYmVyOgogICAgICAgICAgICAgICAgcHJpbnQgKCJDb25ncmFkdWxhdGlvbnMhIFlvdXIgc2NvcmUgaXMgIit0cmllczErIi4gUmVydW4gdGhlIHByb2dyYW0gdG8gZG8gaXQgYWdhaW4hIikKICAgICAgICAgICAgICAgIHRpbWUuc2xlZXAoNSkKICAgICAgICAgICAgaWYgaW50KGd1ZXNzKSAhPSBudW1iZXIgYW5kIHRyaWVzID49IDE6CiAgICAgICAgICAgICAgICBwcmludCgiXG4gVHJpZXMgbGVmdDoiICsgc3RyKHRyaWVzKSkKICAgICAgICAgICAgICAgIGd1ZXNzID0gaW5wdXQoIkFnaCEgU28gY2xvc2UuIFRyeSBhZ2FpblxuIikKICAgICAgICAgICAgICAgIHRyaWVzOiBpbnQgPSB0cmllcyAtIDEKCgogICAgICAgICAgICAgICAgaWYgaW50KGd1ZXNzKSAhPSBudW1iZXI6CiAgICAgICAgICAgICAgICAgICAgcHJpbnQgKCJCb28gaG9vLi4geW91IGxvc3QuIFJlcnVuIHRoZSBwcm9ncmFtIHRob3VnaCEiKQogICAgICAgICAgICAgICAgICAgIHByaW50ICgiXG4gVGhlIGFuc3dlciB3YXMgIitudW1iZXIxKQogICAgICAgICAgICAgICAgICAgIHRpbWUuc2xlZXAoNSkKICAgICAgICAgICAgICAgIGlmIGludChndWVzcykgPT0gbnVtYmVyOgogICAgICAgICAgICAgICAgICAgIHByaW50ICgiQ29uZ3JhdHMhIFlvdSBoYXZlIHdvbiEgWW91IGRvbid0IGhhdmUgYSBzY29yZSB5b3UgZGlkIHNvIGJhZC4gQ29tZSAiLCIgYWdhaW4hIikKICAgICAgICAgICAgICAgICAgICB0aW1lLnNsZWVwKDUpCiAgICAgICAgICAgICAgICAgICAgCmlmIGVudGVyICE9ICJZIjoKICAgIHByaW50ICgiRWl0aGVyLCB5b3UgZG9uJ3Qgd2FudCB0byBwbGF5LCBvciB5b3UgZW50ZXJlZCBhbm90aGVyIG51bWJlci4iKQ=="},"asBuffer":null},"loaded":true}}
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
import random
import math
import time


number = random.randint(1, 10)
number1 = str(number)
tries = 3
tries1 = str(tries)


uname = input("Hello, what is your username? \n")

print ("Hello, " +uname+ "." ,)

enter= input("Would you like to play this game (Guess the number)? (Y for yes, N for no.)\n")



if enter == "Y":
    print ("Welcome then, let us begin.")
    time.sleep(1)
    guess = input("Enter your number, pick wisely, out of ten.\n")


    if int(guess) == number:
        print ("Congrats! You won! the number was "+number1+". Come again!")
        time.sleep(5)
    if int(guess)!= number and tries>=1:
        print ("\n Tries left:"+str(tries))
        guess= input("Agh! So close. Try again \n")
        tries: int = tries - 1


        if int(guess) == number:
            print ("Congrats! You have won! \n", "Your score is "+tries1 +". Rerun the program to do it again!")
            time.sleep(5)
        if int(guess) != number and tries >= 1:
            print("\n Tries left:" + str(tries))
            guess = input("Agh! So close. Try again\n")
            tries: int = (tries - 1)


            if int(guess) == number:
                print ("Congradulations! Your score is "+tries1+". Rerun the program to do it again!")
                time.sleep(5)
            if int(guess) != number and tries >= 1:
                print("\n Tries left:" + str(tries))
                guess = input("Agh! So close. Try again\n")
                tries: int = tries - 1


                if int(guess) != number:
                    print ("Boo hoo.. you lost. Rerun the program though!")
                    print ("\n The answer was "+number1)
                    time.sleep(5)
                if int(guess) == number:
                    print ("Congrats! You have won! You don't have a score you did so bad. Come "," again!")
                    time.sleep(5)
                    
if enter != "Y":
    print ("Either, you don't want to play, or you entered another number.")