Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
January 12th, 2013, 05:26 AM
 cooper_tim13
Registered User

Join Date: Jan 2013
Posts: 3
Time spent in forums: 37 m 11 sec
Reputation Power: 0
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
January 12th, 2013, 11:27 AM
 leonnaley2
Contributing User

Join Date: Jan 2013
Posts: 67
Time spent in forums: 23 h 24 m 55 sec
Reputation Power: 1
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.

#3
January 12th, 2013, 11:53 AM
 leonnaley2
Contributing User

Join Date: Jan 2013
Posts: 67
Time spent in forums: 23 h 24 m 55 sec
Reputation Power: 1
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 ""

#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

#PRINT OUT TOTAL AMOUNT OF SECONDS
print "The total download time would then be " + str(total_download_time) + " seconds"
```

#4
January 12th, 2013, 04:45 PM
 cooper_tim13
Registered User

Join Date: Jan 2013
Posts: 3
Time spent in forums: 37 m 11 sec
Reputation 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...

#5
January 13th, 2013, 05:27 AM
 leonnaley2
Contributing User

Join Date: Jan 2013
Posts: 67
Time spent in forums: 23 h 24 m 55 sec
Reputation Power: 1
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

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

#6
January 13th, 2013, 05:29 AM
 leonnaley2
Contributing User

Join Date: Jan 2013
Posts: 67
Time spent in forums: 23 h 24 m 55 sec
Reputation Power: 1
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.

#7
January 13th, 2013, 05:53 AM
 leonnaley2
Contributing User

Join Date: Jan 2013
Posts: 67
Time spent in forums: 23 h 24 m 55 sec
Reputation Power: 1
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 ""

#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

#PRINT OUT TOTAL AMOUNT OF SECONDS
print "The total download time would then be " + str(total_download_time) + " seconds"

```

#8
January 15th, 2013, 05:00 AM
 cooper_tim13
Registered User

Join Date: Jan 2013
Posts: 3
Time spent in forums: 37 m 11 sec
Reputation Power: 0
Thankyou Thankyou Thankyou!!!!!!!!

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

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need Help! (Don't worry, it's easy)

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |