• 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:
                try:
                    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)
                except:
                    print("error, try again.")
                    continue
            hoursWorked = float(input("Enter hours worked: "))
            salesAmount = float(input("Enter sales amount: "))
            print(salesLevel*salesAmount)
        
    salesPerson()
    

    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.
    Thanks,
    Craig

    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

    Hi,
    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.")
        time.sleep(2)
        
    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)
                    print(question)
                elif (levels == 2):
                    question = choice(cmajor),choice(cmajor)
                    print(question)
                elif (levels == 3):
                    question = choice(cmajor),choice(cmajor),choice(cmajor)
                    print(question)
                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)
                        print(question)
                    elif (levels == 2):
                        question = choice(cminor),choice(cminor)
                        print(question)
                    elif (levels == 3):
                        question = choice(cminor),choice(cminor),choice(cminor)
                        print(question)
    if __name__ == "__main__":
        intro()
        practicing = True
        while practicing: #prompts the user to keep playing
            key(myInterface)
            viewSelector = myInterface.superview
            textFromTextBox = viewSelector['textview1'].text
            time.sleep(2)
            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
            print('Goodbye')
    v = ui.load_view()
    v.present('sheet')
    
    
    

    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.')
        else:
            print('I do not understand your choice.')
            
    key()
    
    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)
                answer=input(question).lower()
                
        elif (ask2=='minor'):
                question = choice(minor)
                answer=input(question).lower()
            
        def level():
            ask = int(input('Choose your level(1, 2, or 3): '))
            if (ask == 1):
                question = choice()
                answer=input(question).lower()
                print(answer)
            elif (ask == 2):
                question = choice(),choice()
                answer=input(question).lower()
                print(answer)
            elif (ask == 3):
                question = choice(),choice(),choice()
                answer=input(question).lower()
                print(answer)
            else:
                print('I do not understand your choice.')
                    
        level()
    tone()
    

    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
    
        else:
            return False #return False if no duplicates are found 
        
        
    has_consecutive()```

    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():
                setattr(self,key,value)
            
            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.age,self.subclass,self.hair,self.eyes,
            self.height,self.weight,self.strength, self.speed,self.intelligence,self.knowledge,
            self.attack,self.defense)
        
    p1 = Player("Rob", "Human", "Hunter", "25", "none", "Brown", "Green", "72in","185"," "," "," "," "," "," ")
    print(p1)
            
    #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)
                }
                super().__init__(**data)
            
    p2 = Vampire("Jon", "Vampire", "Archaea", "500", "none", "Black", "Red", "84in","225"," "," "," "," "," ")
    print(p2)
    

    posted in Pythonista read more
  • craigmrock

    Hi,
    Getting an error that “mode object has no attribute scale_steps” when I run this, but I think everything is ok. Does anyone see where there is a disconnect??

    legal_mode = [ 
        "Ionian", 
        "Dorian",
        "Phrygian",
        "Lydian",
        "Mixolydian",
        "Aeolian",
        "Locrian"]
    stepping = [2, 2, 1, 2, 2, 2, 1]
    major_mode = ["Ionian"]
    
    class Mode():
        def __init__(self,title):
            self.title = title
            self.ismajor = title in major_mode
            tonic = legal_mode.index(title)
            self.stepping = stepping[tonic:]+stepping[:tonic]
            
            def __str__(self):
                return "Title: {}, Major{}".format(self.title, self.ismajor)
                
            def scale_steps(self):
                return "Half-steps{}".format(''.join(str(c) for c in self.stepping))
    
    mode1 = Mode("Ionian")
    print(mode1)
    print(mode1.scale_steps())
    
    mode2 = Mode("Dorian")
    print(mode2)
    print(mode2.scale_steps())```

    posted in Pythonista read more
  • craigmrock

    @ccc thanks, that cleared up one of the errors I was getting through experimenting.
    Craig

    posted in Pythonista read more
  • craigmrock

    Looking to create a database that retrieves scales for guitar practice. At the moment, I just want it to list a major or minor scale when you answer the question: “Major or minor scale?”
    I’m a noob, trying to take some class examples and make them into what I’d like to work on.

    import random
    
    class scale:
        def __init__(self,minor=False, major=True, **kwargs):
            for key,value in kwargs.items():
                setattr(self,key,value)
            
    class Ionian(scale):
        def __init__(self):
            data = {
                "value": 'major'
            }
            super().__init__(**data)
            
    class Dorian(scale):
        def __init__(self):
            data = {
                "value": 'minor'
            }
            super().__init__(**data)
            
    class Phrygian(scale):
        def __init__(self):
            data = {
                "value": 'minor'
            }
            super().__init__(**data)
                
    class Lydian(scale):
        def __init__(self):
            data = {
                "value": 'major'
            }
            super().__init__(**data)
                
    class Mixolydian(scale):
        def __init__(self):
            data = {
                "value": 'major'
            }
            super().__init__(**data)
                
    class Aeolian(scale):
        def __init__(self):
            data = {
                "value":'minor'
            }
            super().__init__(**data)
            
    class Locrian(scale):
        def __init__(self):
            data = {
                "value": 'minor'
            }
            super().__init__(**data)
            
    scales = [Ionian(), Dorian(), Phrygian(), Lydian(), Mixolydian(), Aeolian(), Locrian()]
    
    for scale in scales:
        arguments = [scale,scale.value]
        string = "{}: - value:{}".format(*arguments)
    
    while True:
        choice = input("Major or Minor scale?: ").strip().title()
        
        if choice in scale:
            mode = int(input("Do you like a particular mode?").strip())
    

    posted in Pythonista read more
  • craigmrock

    @jerry thanks!! That worked!

    posted in Pythonista read more
  • craigmrock

    Hi,
    Having trouble with code for a coin flip simulation program I’m trying to set up for a Stats class. The goal is to ask how many times to flip the coin, then show the results after the simulation. I’m pretty new to Python and programming, so I checked stack overflow and found the code below to try. Problem is, nothing is printing to the console to review. Any thoughts?

    import random
    
    def coinToss():
        number = input("Number of times to flip coin: ")
        recordList = []
        heads = 0
        tails = 0
        for amount in range(number):
            flip = random.randint(0,1)
            if (flip == 0):
                print("Heads")
                recordList.append("Heads")
            else:
                print("Tails")
                recordList.append("Tails")
            print(str(recordList))
            print(str(recordList.count("Heads")) + str(recordList.count("Tails")))
            
        
    
            
        ```

    posted in Pythonista read more
  • craigmrock

    @dgelessus thanks again, I just deleted the heads line and it ran fine. I’ll be sure to include your reference tips in future posts too.
    Craig

    posted in Pythonista read more
  • craigmrock

    @dgelessus thanks! That helped there. I got a new error message saying that
    heads is not defined
    At line 10, but I thought it was ok. There also appears to be errors at line 52 and 169 Here is my code below

    import random

    class Coin:
    def init(self,rare=False, clean=True, **kwargs):
    for key,value in kwargs.items():
    setattr(self,key,value)

        self.is_rare = rare
        self.is_clean = clean
        self.heads = heads
        
        if self.is_rare:
            self.value = self.original_value * 1.25
        else:
            self.value = self.original_value
            
        if self.is_clean:
            self.color = self.clean_color
        else:
            self.color = self.rusty_color
    
    def rust(self):
        self.color = self.rusty_color
        
    def clean(self):
        self.color = self.clean_color
        
    def __del__(self):
        print("Coin Spent!")
        
    def flip(self):
        heads_options = [True,False]
        choice = random.choice(heads_options)
        self.heads = choice
        
    def __str__(self):
        if self.original_value >= 1.00:
            return "£{}Coin".format(int(self.original_value))
        else:
            return "{}p Coin".format(int(self.original_value * 100))
    

    class One_Pence(Coin):
    def init(self):
    data = {
    "original_value": 0.01,
    "clean_color": "bronze",
    "rusty_color": "brownish",
    "num_edges": 1,
    "diameter": 20.3,
    "thickness": 1.52,
    "mass": 3.56
    }
    super().init(**data)

    class Two_Pence(Coin):
    def init(self):
    data = {
    "original_value": 0.02,
    "clean_color": "bronze",
    "rusty_color": "brownish",
    "num_edges": 1,
    "diameter": 25.9,
    "thickness": 1.85,
    "mass": 7.12,
    }
    super().init(**data)

    class Five_Pence(Coin):
    def init(self):
    data = {
    "original_value": 0.05,
    "clean_color": "silver",
    "rusty_color": None,
    "num_edges": 1,
    "diameter": 18.0,
    "thickness": 1.77,
    "mass": 3.25,
    }
    super().init(**data)

        def rust(self):
            self.color = self.clean_color
            
        def clean(self):
            self.color = self.clean_color
    

    class Ten_Pence(Coin):
    def init(self):
    data = {
    "original_value": 0.10,
    "clean_color": "silver",
    "rusty_color": None,
    "num_edges": 1,
    "diameter": 24.5,
    "thickness": 1.85,
    "mass": 6.50,
    }
    super().init(**data)

        def rust(self):
            self.color = self.clean_color
            
        def clean(self):
            self.color = self.clean_color
    

    class Twenty_Pence(Coin):
    def init(self):
    data = {
    "original_value": 0.20,
    "clean_color": "silver",
    "rusty_color": None,
    "num_edges": 1,
    "diameter": 21.4,
    "thickness": 1.7,
    "mass": 5.0,
    }
    super().init(**data)

        def rust(self):
            self.color = self.clean_color
            
        def clean(self):
            self.color = self.clean_color
    

    class Fifty_Pence(Coin):
    def init(self):
    data = {
    "original_value": 0.50,
    "clean_color": "silver",
    "rusty_color": None,
    "num_edges": 7,
    "diameter": 27.3,
    "thickness": 1.78,
    "mass": 8.0,
    }
    super().init(**data)

        def rust(self):
            self.color = self.clean_color
            
        def clean(self):
            self.color = self.clean_color
    

    class One_Pound(Coin):
    def init(self):
    data = {
    "original_value": 1.00,
    "clean_color": "gold",
    "rusty_color": "greenish",
    "num_edges": 1,
    "diameter": 22.5,
    "thickness": 3.15,
    "mass": 9.5
    }
    super().init(**data)

    class Two_Pound(Coin):
    def init(self):
    data = {
    "original_value": 2.00,
    "clean_color": "gold & silver",
    "rusty_color": "greenish",
    "num_edges": 1,
    "diameter": 28.4,
    "thickness": 2.50,
    "mass": 12.00,
    }
    super().init(**data)

    coins = [One_Pence(), Two_Pence(), Five_Pence(), Ten_Pence(), Twenty_Pence(), One_Pound(), Two_Pound()]

    for coin in coins:
    arguments = [coin, coin.color, coin.value, coin.diameter, coin.thickness, coin.num_edges, coin.mass]
    string = "{}: - Color: {}, value:{}, diameter(mm):{}, thickness(mm):{}, number of edges:{}, mass(g):{}".format(*arguments)
    print(string)

    posted in Pythonista read more
  • craigmrock

    Trying to make a class with the following line of code that pythonista doesn’t like but works fine in idle
    def__init__(self, rare=False):
    Why doesn’t this work here?

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!