Python Forum
How to call the stored values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call the stored values
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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()
Reply
#4
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
Reply
#5
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()
Reply
#6
Cool that does do what i wanted
Now if only i could understand why XD
Reply
#7
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python call stored procedure mg24 2 1,028 Oct-18-2022, 02:19 AM
Last Post: mg24
  python call stored procedure with two parameter mg24 4 1,401 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,196 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Values not updating for restful call boomramada 0 1,623 Mar-13-2021, 01:08 PM
Last Post: boomramada
  How to call the values at the end of a text string? Dieselkaine 2 2,931 Jul-02-2018, 08:47 PM
Last Post: Dieselkaine

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020