Closed Thread
Results 1 to 3 of 3

Thread: Saving Values HELP! - New to codecall and Python!

  1. #1
    Justin2Hale is offline Newbie
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Unhappy Saving Values HELP! - New to codecall and Python!

    Hello! I'm new to codecall and Python, so please bear with me (though, feel free to call me a n00b lol).

    Okay, so I'm working on my project, and it wants me to save the values at the end of the program. In my case, I subtract 1000 from the highPriority. Once this happens at the end, it doesn't change the initial value, leaving me with 3000 as my highPriority. What I want it to do is subtract the input of 1000 from the 3000 and KEEP IT lol. maybe reference values or something with the loops? again, I'm completely new to Python and have been at this for 4 hours.

    here is the code:
    Code:
    def main():
        choice = 0
        highPriority = 3000
        mediumPriority = 5000
        lowPriority = 9000
        while choice != 3:
            print "1: Add Backup Item"
            print "2: Remove Backup Item"
            print "3: Exit"
            choice = input('What do you want to do?')
            if choice == 1:
                addBackupItem(highPriority, mediumPriority, lowPriority)
            elif choice == 2:
                removeBackupItem()
            elif choice == 3:
                print "Goodbye!"
            else:
                print "Invalid selection there, Champ."
        return choice + highPriority + mediumPriority + lowPriority
    
    def addBackupItem(highPriority , mediumPriority , lowPriority):
        backupSize = 10000
        while backupSize > 9000:
            backupSize = input('What is the size of the item you wish to backup?')
            if backupSize >9000:
                print "The size you typed is invalid, please try again."
            else:
                calcPriorityLevel(backupSize, highPriority , mediumPriority , lowPriority)
        return backupSize + highPriority + mediumPriority + lowPriority
        
    def removeBackupItem():
        print
        
    def calcPriorityLevel(backupSize, highPriority, mediumPriority, lowPriority):
        priorityLevel = 4
        while priorityLevel >= 3:
            print "1: High Priority - ", highPriority
            print "2: Medium Priority - ", mediumPriority
            print "3: Low Priority - ", lowPriority
            priorityLevel = input('What is the priority level?')
            if priorityLevel == 1:
                frequency = input('How many times per week will this be backed up?')
                frequency = frequency * backupSize
                printHighPriority(frequency, highPriority)
            elif priorityLevel == 2:
                frequency = input('How many times per week will this be backed up?')
                frequency = frequency * backupSize
                chosenPLevel = mediumPriority
            elif priorityLevel == 3:
                frequency = input('How many times per week will this be backed up?')
                frequency = frequency * backupSize
                chosenPLevel = lowPriority
            else:
                print "Choose 1-3, Chief."
        return frequency + highPriority + mediumPriority + lowPriority
    
    def printHighPriority(frequency, highPriority):
        if frequency > highPriority:
            print "The size you typed is invalid, please try again."
        else:
            print "Backing up..."
            highPriority = highPriority - frequency
            print "Your priority size is now: ", highPriority
        return highPriority
        
    main()
    Any help would be greatly appreciated, and again I'm a n00b lol.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Root23 is offline Programmer
    Join Date
    Jan 2010
    Posts
    144
    Rep Power
    8

    Re: Saving Values HELP! - New to codecall and Python!

    I'm not sure if you ever got your code working properly, but I'll repost what I had posted already.

    As I said before.. I don't know if part of the assignment was for you to use as many function definitions, because I didn't use them in my code, except for printing a list.

    I might have made more of an effort to use them, but I have never used them before(I'm really new to programming). I couldn't get the one instance I did use it to work 100% correct. For some reason it prints 'None' at the end when I use it.

    Anyways, here is the code I have. It's really simple.
    Note: I did leave out section 2; removing a backup.

    Code:
    #CodeCall
    #root23
    
    choice = 0
    highPriority = 3000
    mediumPriority = 5000
    lowPriority = 9000
    
    def levels():
        print "A: High Priority -", highPriority 
        print "B: Medium Priority -", mediumPriority
        print "C: Low Priority -", lowPriority
        
    while True:
        print "1: Add Backup Item"
        print "2: Remove Backup Item"
        print "3: Exit"
        choice = int(raw_input("What do you want to do? "))
    
        if choice == 1:
            print levels()
            priority = raw_input("What is the priority level? ")
            if priority.lower() == "a":
                size = int(raw_input("What is the size of the data to be backed up? "))
                frequency = int(raw_input("How many times will the data be backed up? "))
                backUp = size * frequency
                if backUp > highPriority:
                    print "There is not enough disk space for your backup."
                else:
                    highPriority -= backUp
                    print "Your remaining storage space is ", highPriority
    
            elif priority.lower() == "b":
                size = int(raw_input("What is the size of the data to be backed up? "))
                frequency = int(raw_input("How many times will the data be backed up? "))
                backUp = size * frequency
                if backUp > mediumPriority:
                    print "There is not enough disk space for your backup."
                else:
                    mediumPriority -= backUp
                    print "Your remaining storage space is ", mediumPriority
    
            elif priority.lower() == "c":
                size = int(raw_input("What is the size of the data to be backed up? "))
                frequency = int(raw_input("How many times will the data be backed up? "))
                backUp = size * frequency
                if backUp > lowPriority:
                    print "There is not enough disk space for your backup."
                else:
                    lowPriority -= backUp
                    print "Your remaining storage space is ", lowPriority
    
        elif choice == 2:
            print
            
        elif choice == 3:
            raw_input("Press the enter key to exit.")
            break
    
        else:
            print "You entered an invalid choice."

  4. #3
    Justin2Hale is offline Newbie
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Re: Saving Values HELP! - New to codecall and Python!

    I'll put ya out of your misery

    I received help from my boss lady at my internship, and she said this was the most understandable way:

    Code:
    #Justin Hale - My Final Project
    
    beginHighPriority = 3000
    beginMediumPriority = 5000
    beginLowPriority = 9000
    
    highPriority = beginHighPriority
    mediumPriority = beginMediumPriority
    lowPriority = beginLowPriority
    
    def main():
        choice = 0
        while choice !=3:
            print "MAIN MENU"
            print "---------"
            print "1: Add Backup Item"
            print "2: Remove Backup Item"
            print "3: Exit"
            print
            choice = input('What do you want to do? ')
            if choice == 1:
                addBackupItem()
            elif choice == 2:
                removeBackupItem()
            elif choice == 3:
                print
                print "----------"
                print "Goodbye!"
                print "----------"
            else:
                print "Invalid selection there, Champ."
    
    def invalidStart():
            print
            print "-------------------------------------------"
            print "UH-OH!"
            print "The size you typed is too big or invalid, please try again."
            print "-------------------------------------------"
            print
    
    def addBackupItem():
        addSize = 9001
        while addSize > 9000:
            print
            print "1: High Priority -", highPriority, "MB of", beginHighPriority, "MB is free."
            print "2: Medium Priority - ", mediumPriority, "MB of", beginMediumPriority, "MB is free."
            print "3: Low Priority - ", lowPriority, "MB of", beginLowPriority, "MB is free."
            print
            addSize = input('What is the size (in MB) of the item you wish to backup? ')
            if addSize >9000:
                invalidStart()
            else:
                addPriorityLevel(addSize)
        return addSize
    
    def removeBackupItem():
        removeSize = 9001
        while removeSize > 9000:
            print
            print "1: High Priority - ", highPriority, "MB of", beginHighPriority, "MB is free."
            print "2: Medium Priority - ", mediumPriority, "MB of", beginMediumPriority, "MB is free."
            print "3: Low Priority - ", lowPriority, "MB of", beginLowPriority, "MB is free."
            print
            removeSize = input('What is the size (in MB) of the item that you previously backed up? ')
            if removeSize >9000:
                invalidStart()
            else:
                removePriorityLevel(removeSize)
        return removeSize
    
    def addPriorityLevel(addSize):
        aPriorityLevel = 4
        while aPriorityLevel > 3:
            print
            aPriorityLevel = input('What is the priority level? (Please choose 1-3): ')
            if aPriorityLevel == 1:
                print
                frequency = input('How many times per week will this be backed up? ')
                frequency = frequency * addSize
                addHighPriority(frequency)
            elif aPriorityLevel == 2:
                print
                frequency = input('How many times per week will this be backed up? ')
                frequency = frequency * addSize
                addMediumPriority(frequency)
            elif aPriorityLevel == 3:
                print
                frequency = input('How many times per week will this be backed up? ')
                frequency = frequency * addSize
                addLowPriority(frequency)
            else:
                print
                print "Choose 1-3, Chief."
        return aPriorityLevel
    
    def removePriorityLevel(removeSize):
        rPriorityLevel = 4
        while rPriorityLevel > 3:
            print
            rPriorityLevel = input('What priority level is it located in? (Please choose 1-3): ')
            if rPriorityLevel == 1:
                print
                frequency = input('How many times per week was this backed up? ')
                frequency = frequency * removeSize
                removeHighPriority(frequency)
            elif rPriorityLevel == 2:
                print
                frequency = input('How many times per week was this backed up? ')
                frequency = frequency * removeSize
                removeMediumPriority(frequency)
            elif rPriorityLevel == 3:
                print
                frequency = input('How many times per week was this backed up? ')
                frequency = frequency * removeSize
                removeLowPriority(frequency)
            else:
                print
                print "Choose 1-3, Chief."
        return rPriorityLevel
    
    def addHighPriority(frequency):
        global highPriority
        if frequency > highPriority:
            invalidStart()
        else:
            print
            print "-------------------------------------------"
            print "Backing up..."
            highPriority = highPriority - frequency
            print "Your priority size is now:", highPriority, "MB"
            print "-------------------------------------------"
            print
    
    def removeHighPriority(frequency):
        global highPriority
        if frequency > (beginHighPriority - highPriority):
            invalidStart()
        else:
            print
            print "-------------------------------------------"
            print "Freeing up..."
            highPriority = highPriority + frequency
            print "Your priority size is now: ", highPriority, "MB"
            print "-------------------------------------------"
            print
    
    def addMediumPriority(frequency):
        global mediumPriority
        if frequency > mediumPriority:
            invalidStart()
        else:
            print
            print "-------------------------------------------"
            print "Backing up..."
            mediumPriority = mediumPriority - frequency
            print "Your priority size is now: ", mediumPriority, "MB"
            print "-------------------------------------------"
            print
    
    def removeMediumPriority(frequency):
        global mediumPriority
        if frequency > (beginMediumPriority - mediumPriority):
            invalidStart()
        else:
            print
            print "-------------------------------------------"
            print "Freeing up..."
            mediumPriority = mediumPriority + frequency
            print "Your priority size is now: ", mediumPriority, "MB"
            print "-------------------------------------------"
            print
    
    def addLowPriority(frequency):
        global lowPriority
        if frequency > lowPriority:
            invalidStart()
        else:
            print
            print "-------------------------------------------"
            print "Backing up..."
            lowPriority = lowPriority - frequency
            print "Your priority size is now: ", lowPriority, "MB"
            print "-------------------------------------------"
            print
    
    def removeLowPriority(frequency):
        global lowPriority
        if frequency > (beginLowPriority - lowPriority):
            invalidStart()
        else:
            print
            print "-------------------------------------------"
            print "Freeing up..."
            lowPriority = lowPriority + frequency
            print "Your priority size is now: ", lowPriority, "MB"
            print "-------------------------------------------"
            print
    
    main()
    It makes plenty of sense once you look at it long enough, and is pretty ingenius.

    The global constants are referenced to the global variables, which in turn change at the add or remove stage.

    there's another, less code-yet super complicated way, that I'll post once I can wrap my head around it and finish it

    Thank you guys very much for the effort though!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Advanced Python, part 1: Extending Python with C
    By spyder in forum Python Tutorials
    Replies: 0
    Last Post: 07-31-2010, 09:36 AM
  2. Replies: 11
    Last Post: 07-31-2010, 12:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts