• craigmrock

    Trying to store my calculations in one function and call it in my input function to output a total. If level 1 is selected, I want it to find level 1 in the get_sales function and multiply that percentage by the salesAmount variable in the salesPerson function.

    def get_sales(s):
        level1 = 0
        if s <= 2500:
            level1 = s * 0.045
        return level1
    def salesPerson():
        salesNum = input("How many sales persons? ")
        for num in salesNum:
            salesName = input("Enter sales person name: ")
            salesLevel = 0
            while salesLevel == 0:
                    salesLevel = int(input("Enter sales person level: "))
                    if salesLevel < 1 or salesLevel > 4:
                        print("error, try again.")
                        salesLevel = int(input("Enter sales person level: "))
                        if salesLevel == 1:
                            salesLevel = get_sales(salesLevel)
                    print("error, try again.")
            hoursWorked = float(input("Enter hours worked: "))
            salesAmount = float(input("Enter sales amount: "))

    posted in Pythonista read more
  • craigmrock

    Hi, working on UI layout and want to know how to get a photo from my camera roll or my iCloud Drive to display in the UI grid.

    posted in Pythonista read more
  • craigmrock

    @mikael they aren’t named myInterface, but they are both named the same thing, GOapp.py and GOapp.pyui in the same folder

    posted in Pythonista read more
  • craigmrock

    @cvp I’m not sure how to show that here, I don’t see adding a picture/screenshot option and my UI file only shows the grid layout. I thought I had accessed a code version before, but every button I press in the menu seems to take me everywhere but where the code is (using my iPhone, not a tablet).

    posted in Pythonista read more
  • craigmrock

    I’m looking to get my pythonista code into app mode, and I’m looking for some advice from others. I created the UI folder so I have a UI file and a Python file. The only tutorials I can find are for different types of games.
    I need to figure out how to incorporate my code into the UI layout. Thoughts?
    This is my code, the console says I haven’t defined myInterface, so I need help with that.

    import ui
    import time
    from random import choice
    def intro():
        print("The Guitar Oracle is listening.")
    def key (myInterface):
        viewSelector = myInterface.superview
        textFromTextBox = viewSelector['textview1'].text
        keys = ['C','F','Bb','Eb','Ab','Db','Gb', 'Cb','G','D','A','E','B','F#','C#']
        key = input("Choose your key: ").capitalize()
        if (key == 'C'):
            print('You chose C, excellent')
            ask=input('Major or Minor?: ').lower()
            if (ask=='major'):
                cmajor = ['C Ionian: C – D – E – F – G – A – B','C Lydian: C - D - E - F# - G - A - B','C Mixolydian: C - D - E - F - G - A - Bb', 'C Maj Pentatonic: C - D - E - G - A']
                levels= input('Choose your level (1, 2, or 3): ')
                validLevel = range(1,4) #provides range for acceptable levels 1, 2, or 3
                if (levels.isnumeric()):
                    levels = int(levels)
                if (levels == 1):
                    question = choice(cmajor)
                elif (levels == 2):
                    question = choice(cmajor),choice(cmajor)
                elif (levels == 3):
                    question = choice(cmajor),choice(cmajor),choice(cmajor)
                if (ask=='minor'):
                    cminor = ['C Dorian: C - D - Eb - F - G - A - Bb','C Phrygian: C - Db - Eb - F - G - Ab - Bb', 'C Aeolian: C - D - Eb - F - G - Ab - Bb','C Locrian: C - Db - Eb - F - Gb - Ab - Bb', 'C Harmonic Minor: C - D - Eb - F - G - Ab - B','C Melodic Minor: C - D - Eb - F - G - A - B','C Min Pentatonic: C - Eb - F - G - Bb']
                    levels= input('Choose your level (1, 2, or 3): ')
                    validLevel = range(1,4) #provides range for acceptable levels 1, 2, or 3
                    if (levels.isnumeric()):
                        levels = int(levels)
                    if (levels == 1):
                        question = choice(cminor)
                    elif (levels == 2):
                        question = choice(cminor),choice(cminor)
                    elif (levels == 3):
                        question = choice(cminor),choice(cminor),choice(cminor)
    if __name__ == "__main__":
        practicing = True
        while practicing: #prompts the user to keep playing
            viewSelector = myInterface.superview
            textFromTextBox = viewSelector['textview1'].text
            keepPracticing = input('Do you want to keep practicing (yes or no)? ')
            validUser = ['yes', 'y','sure','ok','k','okay'] #acceptable answers for keepPracticing
            if (keepPracticing not in validUser): practicing = False #terminates program/loop
    v = ui.load_view()

    posted in Pythonista read more
  • craigmrock

    Trying to build a 3 function program:

    1. What key(music)?
    2. Major or minor?
      3.What level (for practicing)?
      Having trouble with local variables I think. The steps should be: get the key, decide between major or minor scales, then determine how many scales to provide, 1, 2, or 3?
      I have this working properly without functions but believe there’s a cleaner way to write it.
    from random import choice
    def key():
        keys = ['A','B','C','D','E','F','G']
        k1=input('Choose your key: ').upper()
        if k1 in keys:
            print('Ahh,',k1, 'excellent choice.')
            print('I do not understand your choice.')
    def tone():
        major = ['Ionian: W,W,H,W,W,W,H','Lydian: W,W,W,H,W,W,H','Mixolydian: W,W,H,W,W,H']
        minor= ['Dorian: W,H,W,W,W,H,W','Phrygian: H,W,W,W,H,W,W','Aeolian: W,H,W,W,H,W,W','Locrian: H,W,W,H,W,W,W','Harmonic Minor: W,H,W,W,H,W+H,H']
        ask2 = input('Major or Minor: ')
        if (ask2=='major'):
                question = choice(major)
        elif (ask2=='minor'):
                question = choice(minor)
        def level():
            ask = int(input('Choose your level(1, 2, or 3): '))
            if (ask == 1):
                question = choice()
            elif (ask == 2):
                question = choice(),choice()
            elif (ask == 3):
                question = choice(),choice(),choice()
                print('I do not understand your choice.')

    posted in Pythonista read more
  • craigmrock

    Trying to return True if there are duplicate items in a list.
    Not working with numbers, and want to allow the user to make a list as long as they want...suggestions?

    user = input("What's on your list??: ")
    def has_consecutive():
        items = user.split() #trying to split list into items to compare
        if (items[0] == items[+1]): #trying to compare one item to the next to find duplicates
            return True #return true if duplicates are found
            return False #return False if no duplicates are found 

    posted in Pythonista read more
  • craigmrock

    Horrible at math (and probably Python) but trying to make a function that takes a word and adds an asterisk in between the letters. Trying with a 3 letter word, but the formula should handle any size word you give it.
    Here’s what I have:

    word=str(input('Give me a word: '))
    def starry_eyes(str):
        while word == (''):
            return ([],'*',[],'*',[])

    posted in Pythonista read more
  • craigmrock

    Thinking I set up this inheritance structure right, but getting an error that “ init() takes 1 positional argument but 15 were given.” Any thoughts?

    import random
    #Player Info
    class Player:
        def __init__ (self, name, race, subrace, age, subclass,hair, eyes, height, weight, strength, speed, intelligence, knowledge, attack, defense,**kwargs):
            for key,value in kwargs.items():
            self.name = name
            self.race = race
            self.subrace = subrace
            self.age = age
            self.subclass = subclass
            self.hair = hair
            self.eyes = eyes
            self.height = height
            self.weight = weight
            self.strength = random.randint(6,18)
            self.speed = random.randint(6,18)
            self.intelligence = random.randint(6,18)
            self.knowledge = random.randint(6,18)
            self.attack = random.randint(2,6)
            self.defense = random.randint(2,6)
        def __str__ (self):
            return ("Name: {}, Race: {}, Subrace: {}, Age: {}, Subclass: {}, Hair: {}, Eyes: {}, Height: {}, Weight:{}, Strength: {}, Speed: {}, Intelligence: {}, Knowledge: {}, Attack: {}, Defense: {}").format(self.name,self.race,self.subrace,
            self.height,self.weight,self.strength, self.speed,self.intelligence,self.knowledge,
    p1 = Player("Rob", "Human", "Hunter", "25", "none", "Brown", "Green", "72in","185"," "," "," "," "," "," ")
    #Special Classes for Players
    class Vampire(Player):
            def __init__ (self):
                data = {
                    "strength": random.randint(14,18),
                    "speed": random.randint(14,18),
                    "intelligence": random.randint(14,18),
                    "knowledge": random.randint(14,18)
    p2 = Vampire("Jon", "Vampire", "Archaea", "500", "none", "Black", "Red", "84in","225"," "," "," "," "," ")

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!