Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Having problems with this assignment

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-06-2011, 07:04 AM PM User | #1 tridentspk New Coder   Join Date: Jul 2011 Posts: 17 Thanks: 2 Thanked 0 Times in 0 Posts Having problems with this assignment Hey guys, So I have this last question in my python lab Its question # 6 on this page (on the right hand column): http://goo.gl/rqDwS My problem is figuring out how to make a loop that checks for each number between 1 and the input N. For example, if N = 12, I'll need to print a table of numbers from 1-12 and displaying whether each number is perfect, abundant, or deficient. So far I have only written code that determines what status the value of input N is. Code: ```def print_table(n): i = 1 add = 0 last = n - 1 count = n while i <= last: if count % i == 0: add = add + i i = i + 1 msg = '' if add < n: msg = 'is deficient' elif add == n: msg = 'is perfect' elif add > n: msg = 'is abundant' print n, msg number = int(input("Enter a number: ")) print_table(number)``` The output of the program should look like this: Code: ```Enter a number: 12 12 abundant 11 deficient 10 deficient 9 deficient 8 deficient 7 deficient 6 perfect 5 deficient 4 deficient 3 deficient 2 deficient 1 perfect``` Now here is the logic behind it: 12 < 1 + 2 + 3 + 4 + 6 11 > 1 10 > 1 + 2 + 5 9 > 1 + 3 8 > 1 + 2 + 4 7 > 1 6 = 1 + 2 + 3 5 > 1 4 > 1 + 2 3 > 1 2 > 1 1 = 1 So thats why I was thinking of having some kind of while loop that produces different variables like add11, add10, add9, etc to store the sum of the numbers that leave a remainder of 0. But that doesn't seem to be possible. Thanks for any help on this
 12-10-2011, 03:50 AM PM User | #2 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts Just do something like: while i > 0: print_table(i) i--

 Bookmarks

 Thread Tools Rate This Thread 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 BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:13 AM.