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 Warning: integer argument expected, got float

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-22-2011, 06:22 PM PM User | #1 KevinJohnson Regular Coder   Join Date: May 2009 Location: China Posts: 133 Thanks: 1 Thanked 1 Time in 1 Post Warning: integer argument expected, got float i'm getting the following error when trying to divide by numbers inside of a list. I'm a little new to Python, and i was wondering how i can fix this problem. sphere.py:23: Deprecation Warning: integer argument expected, got float for y in range(notch[x] / 360): Code: ```import math ## Generate a Sphere in 3d Space def sphere(r, lx, ly, lz): for i in range(0,360): lx.append(math.cos(i) * r) ly.append(math.sin(i) * r) lz.append(math.cos(i) * r) ## Generate a list of possible Lock positions def GenPositions(NotchList, n): notch = [] a1 = 180 r = .5 # Generate a List of Smallest Slice angles for i in range(n): notch.append(a1 * (r ** (i-1))) # Generate a final list of Notches for x in range(1,len(notch)): for y in range(notch[x] / 360): NotchList.append(notch[x] * y) # Test - Generate sphere coordinates lx = [] ly = [] lz = [] tmp = sphere(10, lx, ly, lz) for i in range(len(lx)): print lx[i], ly[i], lz[i] print print "There are " + str(len(lx)) + " vertices" # Test - Generate Lock positions NotchList = [] tmp = GenPositions(NotchList, 64) for i in range(1,len(NotchList)): print i, NotchList[i]```
 12-22-2011, 09:17 PM PM User | #2 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts notch[x] is not guaranteed to be an integer. You may want to do: `int(round(notch[x]))` Edit: It is not guaranteed to be an integer because you are assigning it a value that makes use of r, which is a float. Range requires an integer to generate a number from 0 to that number-1. Last edited by Apothem; 12-22-2011 at 09:29 PM..
12-23-2011, 05:42 AM   PM User | #3
KevinJohnson
Regular Coder

Join Date: May 2009
Location: China
Posts: 133
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
 Originally Posted by Apothem notch[x] is not guaranteed to be an integer. You may want to do: `int(round(notch[x]))` Edit: It is not guaranteed to be an integer because you are assigning it a value that makes use of r, which is a float. Range requires an integer to generate a number from 0 to that number-1.

The problem is that 360 will always be divided by a float, and i need to store the result in a resultant list somewhere for later manipulation..... how exactly do i do that?

Or...should i use a different kind of loop structure?

 12-23-2011, 04:49 PM PM User | #4 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts Well again `int(round(notch[x]))`. It doesn't assign the rounded number, it just converts it for usage.
 12-25-2011, 01:14 AM PM User | #5 Samhain13 Regular Coder     Join Date: Aug 2008 Location: Pilipinas Posts: 165 Thanks: 4 Thanked 18 Times in 18 Posts notch[x]/360 is likely going to be a float anyway, regardless of whether notch[x] were rounded. And the problem is, range simply doesn't want floats; hence, the Deprecation Warning. I believe "a different kind of loop structure" is truly in order. __________________ I am a Man of Truth. I am a Free Human Person. I am a Peacemaker. ** Independent Multimedia Artist in Pasig **
02-27-2012, 11:35 AM   PM User | #6
KevinJohnson
Regular Coder

Join Date: May 2009
Location: China
Posts: 133
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
 Originally Posted by Samhain13 notch[x]/360 is likely going to be a float anyway, regardless of whether notch[x] were rounded. And the problem is, range simply doesn't want floats; hence, the Deprecation Warning. I believe "a different kind of loop structure" is truly in order.
You're right. What's needed is a "While... loop" structure.

i think it's ok, learning any new language has it's ins and outs. i'm learning them as i go.

 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 02:32 PM.