Python Forum

Full Version: How to call the stored values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Complete beginner
I don't know how to get the player choice to return the values stored in alpha

### The idea is to have the player play against the computer without knowing the values of their choices 
### then to guess the high middle low choice

import random

def alpha(*values):
    alpha.values = values or alpha.values
    return alpha.values
alpha.values =()

def bravo(*values):
    bravo.values = values or bravo.values
    return bravo.values
bravo.values =()

alpha(5, 3, 2)
a, b, c = alpha()

bravo(2, 5, 3)
d, e, f = bravo()

def choice():
    choice = ""
    while choice != "a" and choice != "b" and choice != "c":
        print ("choose a, b or c")
        choice = input()
    print (choice) 

    return str(choice)

def check(choice):
    compmove = (d, e, f)
    comp = random.choice (compmove)
    print (comp) 
    
    
    if (choice) == str(comp):
            print("draw")
            print (choice) 
            print (comp)

    elif (choice) > str(comp):
            print ("player")
            print (choice)
            print (comp)
                    
    elif (choice) < str (comp):
            print ("comp")
            print (choice)
            print (comp)

def loop():
    guesses = 0
    while guesses < 6:
        move = choice()
        check(move)
        guesses = guesses +1

loop()
It's not clear to me at all what you are trying to do, but if you want the values stored in alpha, you either need to call alpha or reference alpha.values.
if (choice) == str(comp):
If the player inputs 'a', inside check() are comparing 2 single chars (eg 'a' and '3').
Maybe you can use a dictionary to get the number of the letter coming from input()
in the above code a = 5 just like e = 5
print (a + e) would give you 10
but when it prints the player choice a, it will return a
but when it prints the comp choice e, it will print 5
I want to convert the player choice back into the integer stored in alpha
so it can evaluate them correctly in the check block

hope that explains it better
I tried to keep your logic.

# The idea is to have the player play against the computer without knowing the values of their choices
# then to guess the high middle low choice

import random

d_moves = {}


def alpha(**kwargs):
    if(d_moves):
        # Merge if d_moves already exists
        return {**d_moves, **kwargs}
    return kwargs


#def bravo(*values):
#    bravo.values = values or bravo.values
#    return bravo.values
#bravo.values =()


d_moves = alpha(a=5, b=3, c=2)
d_moves = alpha(d=2, e=5, f=3)


def choice():
    choice = ""
    while choice != "a" and choice != "b" and choice != "c":
        print("choose a, b or c")
        choice = input()

    # Get the int using a,b,c as key of the dict
    choice = d_moves[choice]
    return choice


def check(choice):
    compmove = ('d', 'e', 'f')
    comp = random.choice(compmove)
    comp = d_moves[comp]

    if (choice) == (comp):
        print("draw")
        print(choice)
        print(comp)

    elif (choice) > (comp):
        print("player")
        print(choice)
        print(comp)

    elif (choice) < (comp):
        print("comp")
        print(choice)
        print(comp)


def loop():
    guesses = 0
    while guesses < 6:
        move = choice()
        check(move)
        guesses = guesses + 1


loop()
Cool that does do what i wanted
Now if only i could understand why XD
You can use a dictionary directly.
Work with dictionaries in python is very important.

d_moves = {'a': 5, 'b': 3, 'c': 2, 'd': 2, 'e': 5, 'f': 3}
# To access a value of a key: d[key] = value
print(d_moves['a']) # <- prints 5