#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Smile Need Help! (Don't worry, it's easy)


    Hi so I just need help with this little bit in this crappy little python program. This is what I have got so far:

    hangoverA = int(2200000)
    rolemodelsA = int(1005000)
    SHHA = int(4000000)
    skyfallA = int(1250000)
    PGA = int(1500000)
    shrekA = int(800000)

    hello = raw_input("Hello and WELCOME to the Movie Downloader! To start, press ENTER...")
    list1 = raw_input("Press ENTER for the list of movies you can download...")
    print ""
    print "1: The Hangover (2200MB)"
    print "2: Role Models (1005MB)"
    print "3: Summer Heights High (The WHOLE Series) (4000MB)"
    print "4: Skyfall (1250MB)"
    print "5: Parental Guidance (1500MB)"
    print "6: Shrek (800MB)"
    print ""
    print "Note: THERE IS A MAXIMUM OF 1 COPY OF EACH MOVIE..."
    hangover = int(raw_input("How many copies of 'The Hangover' would you like to download?: "))
    rolemodels = int(raw_input("How many copies of 'Role Models' would you like to download?: "))
    summerheightshigh = int(raw_input("How many copies of 'Summer Heights High' would you like to download?: "))
    skyfall = int(raw_input("How many copies of 'Skyfall' would you like to download?: "))
    parentalguidance = int(raw_input("How many copies of 'Parental Guidance' would you like to download?: "))
    shrek = int(raw_input("How many copies of 'Shrek' would you like to download?: "))
    print ""
    internet_speed = int(raw_input("How many KB download p/sec on your computer? "))
    print ""
    hangoverSPEED = hangoverA/internet_speed
    rolemodelsSPEED = rolemodelsA/internet_speed
    SHHASPEED = SHHA/internet_speed
    skyfallSPEED = skyfallA/internet_speed
    PGASPEED = PGA/internet_speed
    shrekSPEED = shrekA/internet_speed

    if hangover >= 1:
    print "It will take", hangoverSPEED, "seconds to download 'The Hangover'"
    if hangoverSPEED > 60:
    print "This can also be written as", hangoverSPEED/60, "minutes."
    print ""
    if rolemodels >= 1:
    print "It will take", rolemodelsSPEED, "seconds to download 'Role Models'"
    print "This can also be written as", rolemodelsSPEED/60, "minutes."
    print""
    if summerheightshigh >= 1:
    print "It will take", SHHASPEED, "seconds to download 'Summer Heights High'"
    print "This can also be written as", SHHASPEED/60, "minutes."
    print""
    if skyfall >= 1:
    print "It will take", skyfallSPEED, "seconds to download 'Skyfall'"
    print "This can also be written as", skyfallSPEED/60, "minutes."
    print ""
    if parentalguidance >= 1:
    print "It will take", PGASPEED, "seconds to download 'Parental Guidance'"
    print "This can also be written as", PGASPEED/60, "minutes."
    print ""
    if shrek >= 1:
    print "It will take", shrekSPEED, "seconds to download 'Shrek'"
    print "This can also be written as", shrekSPEED/60, "minutes."
    print ""

    So basically, the program at the moment gets the user to choose certain movies and then type their internet speed. It will then calculate how long it will take for each movie to download but I also want it to add up all of the SELECTED movie times and put it in an overall time but I can't figure out how to do it ... Please help! Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    2
    hey, if I were to write this code, i would try to use functions, lists, loops and dictionaries.

    Alot of the code you are writing is the same code over and over again, and your variables should be in a list.

    give me a few min, and I'll make an example for you.

    Comments on this post

    • b49P23TIvg agrees : Yes, we abhor duplicate code.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    2
    here you go, hope it helps. if you have any questions, feel free to ask. (this is just one of the many ways to do this.)

    Films is a dictionary which holds names for every film, and if you look up that name you would find a small list with the download size, and number of copies the user wants.

    Code:
    #!/usr/bin/python2
    
    #Makes a dictionary which contains every movie name, and has a list of the download size and number of copies.
    Films={"hangover":[2200000, 0], "rolemodels":[1005000, 0], "SHHA":[4000000, 0], "skyfallA":[1250000, 0], "PGA":[1500000, 0], "Shrek":[800000, 0]}
    
    raw_input("Hello and WELCOME to the Movie Downloader! To start, press ENTER...")
    raw_input("Press ENTER for the list of movies you can download...")
    print ""
    print "1: The Hangover (2200MB)"
    print "2: Role Models (1005MB)"
    print "3: Summer Heights High (The WHOLE Series) (4000MB)"
    print "4: Skyfall (1250MB)"
    print "5: Parental Guidance (1500MB)"
    print "6: Shrek (800MB)"
    print ""
    print "Note: THERE IS A MAXIMUM OF 1 COPY OF EACH MOVIE..."
    
    #LOOPS THROUGH ALL FILMS IN THE DICTIONARY
    for Name in Films:
        #CHANGES THE NUMBER OF COPIES TO WHATEVER THE USER WANTS IN EACH FILM
        Films[Name][1] = int(raw_input("How many copies of the movie " + Name + "would you like to download?"))
    
    
    internet_speed = int(raw_input("How many KB download p/sec on your computer? "))
    print ""
    total_download_time = 0
    
    #LOOPS THROUGH ALL FILMS IN THE DICTIONARY
    for Name in Films:
        #AS LONG AS THE USER WANT A COPY OF THE FILM
        if Films[Name][1] != 0:
            #PRINT OUT SECONDS AND MINUTES IT IS GOING TO TAKE TO DOWNLOAD IT
            print "It will take " + str( Films[Name][0] // internet_speed)  + " seconds to download"
            print "This can also be written as " + str(Films[Name][0] // internet_speed // 60) + " minutes."
            
            #ADD ALL SECONDS TO TOTAL
            total_download_time = total_download_time + (Films[Name][0] // internet_speed)
            
    #PRINT OUT TOTAL AMOUNT OF SECONDS
    print "The total download time would then be " + str(total_download_time) + " seconds"
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Thankyou So Much!


    You are awesome! Thankyou for putting the comments through the program as well. It helped me understand what you were doing. But there is one little problem...

    The program isn't finished.

    I'll show you:

    #PRINT OUT SECONDS AND MINUTES IT IS GOING TO TAKE TO DOWNLOAD IT
    print "It will take " + str( Films[Name][0] // internet_speed) + " seconds to download" <--------- There's nothing there!!! When you run it, it just prints "It will take (number of seconds) seconds to download" but then nothing else prints...

    PLEASE HELP ME! Thanks
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    2
    hey, this is what my output is like, I can't really understands whats missing? except maybe change the text from "It will take 3000 seconds to download" to "The Hangover will take 3000 seconds to download"

    what more text do you want there then?

    OUTPUT:
    Hello and WELCOME to the Movie Downloader! To start, press ENTER...
    Press ENTER for the list of movies you can download...

    1: The Hangover (2200MB)
    2: Role Models (1005MB)
    3: Summer Heights High (The WHOLE Series) (4000MB)
    4: Skyfall (1250MB)
    5: Parental Guidance (1500MB)
    6: Shrek (800MB)

    Note: THERE IS A MAXIMUM OF 1 COPY OF EACH MOVIE...
    How many copies of the movie PGAwould you like to download?1
    How many copies of the movie hangoverwould you like to download?2
    How many copies of the movie skyfallAwould you like to download?0
    How many copies of the movie SHHAwould you like to download?0
    How many copies of the movie rolemodelswould you like to download?0
    How many copies of the movie Shrekwould you like to download?0
    How many KB download p/sec on your computer? 500

    It will take 3000 seconds to download
    This can also be written as 50 minutes.
    It will take 4400 seconds to download
    This can also be written as 73 minutes.
    The total download time would then be 7400 seconds
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    2
    change line 33 to

    print str(Name) + "will take " + str( Films[Name][0] // internet_speed) + " seconds to download"

    if you want it to print the movie title as well.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    2
    here's an even better version of the code. This one uses a function I've created before to check the input from the user, so that the number of copies he wants has to be a number from 0 to 3(not including 3)

    and his download speed would have to be between 1 and 5000.

    it also uses a dictionary which consist of dictionaries, to simply the code abit(so we can write Films["hangover"]["Size"] and get the size for instance.

    Code:
    #!/usr/bin/python2
    
    #DEFINES FUNCTIONS
    def fInput(sText = "", DesiredInput = [],  iNumberFrom = 0, iNumberTo = 0, lUnDesiredInput = []):
        '''
        Takes input from the user and returns it if the input is in lDesiredInput or tNumberBetween but NOT lUnDesiredInput
        '''
        #PRINTS OUT THE TEXT
        print(sText)
        
        #CREATES A LIST OF ALL DESIRED INPUTS(TO HANDLE DESIRED INPUTS THAT ARE NOT A LIST)
        if "list" in str(type(DesiredInput)):
            lDesiredInput = DesiredInput
        else:
            lDesiredInput = [DesiredInput]
        
        #APPENDS ANY NUMBER BETWEEN iNumberFrom and iNumberTo TO THE LIST OF DESIRED INPUTS
        if not (iNumberFrom == 0 and iNumberTo == 0):
            for i in range(iNumberFrom, iNumberTo+1):
                lDesiredInput.append(str(i))
        
        #LOOPS UNTIL THE USER HAS SUPPLIED US WITH A INPUT THATS IN THE LIST OF DESIRED INPUTS BUT
        #   BUT NOT IN THE LIST OF UNDESIRED INPUTS
        while True:
            xInput = str(raw_input())
            if xInput in lDesiredInput and xInput not in lUnDesiredInput:
                return(xInput)
    
    #MAKES A DICTIONARY OF DICTIONARIES, EVERY FILM HAS A DICTONARY NAMED AFTER ITS FILM TITLE
    #   AND ALL THESE DICTIONARIES ARE IN A DICTIONARY CALLED Films
    
    Films={
        "hangover":{"Size":2200000, "Copies":0},
        "rolemodels":{"Size":1005000, "Copies":0},
        "SHHA":{"Size":4000000, "Copies":0},
        "skyfallA":{"Size":1250000, "Copies":0},
        "PGA":{"Size":1500000, "Copies":0},
        "Shrek":{"Size":800000, "Copies":0},
        }
    
    raw_input("Hello and WELCOME to the Movie Downloader! To start, press ENTER...")
    raw_input("Press ENTER for the list of movies you can download...")
    print ""
    print "1: The Hangover (2200MB)"
    print "2: Role Models (1005MB)"
    print "3: Summer Heights High (The WHOLE Series) (4000MB)"
    print "4: Skyfall (1250MB)"
    print "5: Parental Guidance (1500MB)"
    print "6: Shrek (800MB)"
    print ""
    print "Note: THERE IS A MAXIMUM OF 1 COPY OF EACH MOVIE..."
    
    #LOOPS THROUGH ALL FILMS IN THE DICTIONARY
    for Name in Films:
        #CHANGES THE NUMBER OF COPIES TO WHATEVER THE USER WANTS IN EACH FILM
        Films[Name]["Copies"] = int(fInput("How many copies of " + str(Name) + " do you want to download?", iNumberFrom = 0, iNumberTo = 3))
    
    internet_speed = int(fInput("How many Kb can your internet connection download pr second? ", iNumberFrom = 1, iNumberTo = 5001))
    print ""
    total_download_time = 0
    
    #LOOPS THROUGH ALL FILMS IN THE DICTIONARY
    for Name in Films:
        #AS LONG AS THE USER WANT A COPY OF THE FILM
        if Films[Name]["Copies"] != 0:
            #PRINT OUT SECONDS AND MINUTES IT IS GOING TO TAKE TO DOWNLOAD IT
            print str(Name) + "will take " + str( Films[Name]["Size"] // internet_speed)  + " seconds to download"
            print "This can also be written as " + str(Films[Name]["Size"] // internet_speed // 60) + " minutes."
            
            #ADD ALL SECONDS TO TOTAL
            total_download_time = total_download_time + (Films[Name]["Size"] // internet_speed)
            
    #PRINT OUT TOTAL AMOUNT OF SECONDS
    print "The total download time would then be " + str(total_download_time) + " seconds"
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Thankyou Thankyou Thankyou!!!!!!!!


    You are awesome! It works perfectly! Thankyou soooo much!

IMN logo majestic logo threadwatch logo seochat tools logo