Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Jack Cummins
Jack Cummins
17,417 Points

Please help me put levels into action.

# type "pip install emoji" into console for program to work
# INSTUCTIONS
# In this app you are trying to get 10 elevens. You type int how many times you want to run the even_odd function. The number has to be less than 10. What the even_odd function does, is it generates a random number from 1 to 12. Then, it decides if it is even or odd, and if you got a multple of eleven. If you get 10 multiples of eleven, you win! HAVE FUN!
import time
import random
import sys
import emoji
level = 1
evens = 0
odds = 0
elevens = 0
twelves = 0
thirteens = 0
fourteens = 0
fifteens = 0
sixteens = 0
seventeens = 0
eighteens = 0
nineteens = 0
twenties = 0
number_on = ""


def even_odd():
    global evens
    global odds
    global elevens
    global twelves
    global thirteens
    global fourteens
    global fifteens
    global sixteens
    global seventeens
    global eighteens
    global nineteens
    global twenties
    number = random.randint(1, 100)
    if number % 2 == 0:
        print("You got an even number! It was {}!".format(number))
        time.sleep(0.375)
        evens += 1
    else:
        print("You got an odd number! It was {}!".format(number))
        time.sleep(0.375)
        odds += 1
        if level == 1:
            if number == 11 or number == 22 or number == 33 or number == 44 or number == 55 or number == 66 or number == 77 or number == 88 or number == 99:
                print(emoji.emojize('Your number is a multipe of 11! :thumbs_up:'))
                elevens += 1
        elif level == 2:
            if number == 12 or number == 24 or number == 36 or number == 48 or number == 60 or number == 72 or number == 84 or number == 96:
                print(emoji.emojize('Your number is a multipe of 12! :thumbs_up:'))
                twelves += 1
        elif level == 3:
            if number == 13 or number == 26 or number == 39 or number == 52 or number == 65 or number == 78 or number == 91:
                print(emoji.emojize('Your number is a multipe of 13! :thumbs_up:'))
                twelves += 1
        elif level == 4:
            if number == 14 or number == 28 or number == 42 or number == 56 or number == 70 or number == 84 or number == 98:
                print(emoji.emojize('Your number is a multipe of 14! :thumbs_up:'))
                twelves += 1
        elif level == 5:
            if number == 15 or number == 30 or number == 45 or number == 60 or number == 75 or number == 90:
                print(emoji.emojize('Your number is a multipe of 15! :thumbs_up:'))
                twelves += 1
        elif level == 6:
            if number == 16 or number == 32 or number == 48 or number == 64 or number == 80 or number == 94:
                print(emoji.emojize('Your number is a multipe of 16! :thumbs_up:'))
                twelves += 1
        elif level == 7:
            if number == 17 or number == 34 or number == 51 or number == 68 or number == 85:
                print(emoji.emojize('Your number is a multipe of 17! :thumbs_up:'))
                twelves += 1
        elif level == 8:
            if number == 18 or number == 36 or number == 54 or number == 72 or number == 90:
                print(emoji.emojize('Your number is a multipe of 18! :thumbs_up:'))
                twelves += 1
        elif level == 9:
            if number == 19 or number == 38 or number == 57 or number == 76 or number == 95:
                print(emoji.emojize('Your number is a multipe of 19! :thumbs_up:'))
                twelves += 1
        elif level == 10:
            if number == 20 or number == 40 or number == 60 or number == 80 or number == 100:
                print(emoji.emojize('Your number is a multipe of 20! :thumbs_up:'))
                twelves += 1


def main():
    try:
        times_called = int(input("How many times do you want to run the even_odd function? "))
    except:
        print("Sorry, you have to type a number.")
        sys.exit()
    if times_called > 9:
        print("You're only allowed to print the even_odd function 9 times or fewer.")
        sys.exit()
    if times_called <= 0:
        print("Your number has to be between 1 and 9")
        sys.exit()
        global evens
    global odds
    global elevens
    while times_called > 0:
        even_odd()
        times_called -= 1
    print("You have gotten {} odds, {} evens, and {} awesome multiples of the number that you're on.".format(odds, evens, elevens))


def you_win():
    print()
    if elevens >= 10:
        print("You have won the game!")
        sys.exit()
    elif elevens == 9:
        print("You are only one multiple of eleven away from winning the game!")
        print()
    elif elevens == 8:
        print("You are only a couple multiples of eleven away from winning the game!")
    elif elevens == 7 or elevens == 6 or elevens == 5:
        print("You are only a few elevens away from winning the game!")
    elif elevens == 4 or elevens == 3 or elevens == 2 or elevens == 1:
        print("You are many multiples of eleven away from winning the game.")
        print()
    else:
        print("You haven't gotten a single multiple of eleven yet.")


def do_you_want_to_quit():
    want_quit = input("Press enter or return to keep going. Press 'Q' to quit. ").lower()
    if want_quit == "q":
        print("See you next time!")
        sys.exit()


while True:
    main()
    you_win()
    do_you_want_to_quit()

I can't figure out how to use my levels on this. PLEASE HELP! (I give out upvotes and best answers)

Thank you the best! Jack

1 Answer

Steven Parker
Steven Parker
215,939 Points

I don't think I understand the concept of this program, but one logical issue that doesn't make sense is to test if a number is odd and then test to see if that same number was 12 or 24 or 36 ... etc.

Jack Cummins
Jack Cummins
17,417 Points

I know, but that is what I'm doing. I'm just using it to test my coding skill and stretch out my brain. Now anyway, do you have any ideas of how to put the levels into action?

Steven Parker
Steven Parker
215,939 Points

I don't understand the concept of "levels into action". But something like "level == 2" won't do anything if it checks for even numbers on a number already tested to be odd.

Jack Cummins
Jack Cummins
17,417 Points

I have levels, but I don't know how to make them start showing up in the code.