473,583 Members | 3,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'float' / 'int' object is not iterable

90 New Member
I try to calculate the sum of an infinite series
S = Sum (from n=0 to 100) 1/k!
I got message 'float' / 'int' object is not iterable. How can I fix this?
Sep 19 '07 #1
19 23826
bartonc
6,596 Recognized Expert Expert
I try to calculate the sum of an infinite series
S = Sum (from n=0 to 100) 1/k!
I got message 'float' / 'int' object is not iterable. How can I fix this?
Hmmm... I've never seen syntax like that before.. The capital "S" in "Sum" should have thrown the first error in pure Python. ...Then there is the lack of CODE tags in your post..

Expand|Select|Wrap|Line Numbers
  1. >>> sum(range(100))
  2. 4950
  3. >>> 99*50
  4. 4950
  5. >>> 
  6. >>> sum(range(100))/1000
  7. 4
  8. >>> sum(range(100))/1000.0
  9. 4.9500000000000002
  10. >>> 
Sep 19 '07 #2
bartonc
6,596 Recognized Expert Expert
I try to calculate the sum of an infinite series
S = Sum (from n=0 to 100) 1/k!
I got message 'float' / 'int' object is not iterable. How can I fix this?
Infinite, huh? There's got to be some limit:
Expand|Select|Wrap|Line Numbers
  1. >>> sum(xrange(2**16))
  2. 2147450880
  3. >>> sum(xrange(2**32))
  4.   File "<console>", line 1, in ?
  5. ''' exceptions.OverflowError : long int too large to convert to int '''
  6. >>> 
Sep 19 '07 #3
python101
90 New Member
Infinite, huh? There's got to be some limit:
Expand|Select|Wrap|Line Numbers
  1. >>> sum(xrange(2**16))
  2. 2147450880
  3. >>> sum(xrange(2**32))
  4.   File "<console>", line 1, in ?
  5. ''' exceptions.OverflowError : long int too large to convert to int '''
  6. >>> 
yes, that why I limited k to 100
Sep 20 '07 #4
python101
90 New Member
Hmmm... I've never seen syntax like that before.. The capital "S" in "Sum" should have thrown the first error in pure Python. ...Then there is the lack of CODE tags in your post..

Expand|Select|Wrap|Line Numbers
  1. >>> sum(range(100))
  2. 4950
  3. >>> 99*50
  4. 4950
  5. >>> 
  6. >>> sum(range(100))/1000
  7. 4
  8. >>> sum(range(100))/1000.0
  9. 4.9500000000000002
  10. >>> 
it was not the code, only the problem because I could not type the mathematical symbol so I used Sum
Sep 20 '07 #5
bartonc
6,596 Recognized Expert Expert
yes, that why I limited k to 100
Now every one knows... I'm more of a mechanic than a mathematician.
Sep 20 '07 #6
python101
90 New Member
here is what I want to calculate by using Python

Sep 21 '07 #7
KaezarRex
52 New Member
here is what I want to calculate by using Python


This method comes up with the answer 2.71828182846. Is that right?
Expand|Select|Wrap|Line Numbers
  1. def factorial(n):
  2.     if n < 1:
  3.         return 1
  4.     else:
  5.         return n * factorial(n-1)
  6.  
  7. def summation(k, limit):
  8.     if k == limit:
  9.         return 1.0/factorial(k)
  10.     else:
  11.         return 1.0/ factorial(k) + summation(k+1, limit)
  12.  
  13. print summation(0, 100)
Sep 21 '07 #8
bvdet
2,851 Recognized Expert Moderator Specialist
here is what I want to calculate by using Python

Does this work for you?
Expand|Select|Wrap|Line Numbers
  1. def factorial(n):
  2.     if n == 0:
  3.         return 1
  4.     else:
  5.         return n*factorial(n-1)
  6.  
  7. def calc(k, u):
  8.     return float(sum(range(u+1)))/factorial(k)
>>> calc(4, 100)
210.41666666666 666
>>>
Sep 21 '07 #9
python101
90 New Member
This method comes up with the answer 2.71828182846. Is that right?
Expand|Select|Wrap|Line Numbers
  1. def factorial(n):
  2.     if n < 1:
  3.         return 1
  4.     else:
  5.         return n * factorial(n-1)
  6.  
  7. def summation(k, limit):
  8.     if k == limit:
  9.         return 1.0/factorial(k)
  10.     else:
  11.         return 1.0/ factorial(k) + summation(k+1, limit)
  12.  
  13. print summation(0, 100)
yes, it is e - thank you very much
Sep 21 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2075
by: Bengt Richter | last post by:
Peculiar boundary cases: >>> 2.0**31-1.0 2147483647.0 >>> int(2147483647.0) 2147483647L >>> int(2147483647L ) 2147483647 >>> >>> -2.0**31
5
4541
by: Yodai | last post by:
Hi all! I have an int that comes with a value like 0x07fa and I have to turn it into a float value of 204.2 decimal to display it.... if I try to divide it by 10 I get bogus numbers. I presume I have to make it decimal before calculating, but I am not sure about it. Any light upon this simple (or it seems to me so, at least) begginner...
0
1366
by: Travis Oliphant | last post by:
This post is to gather feedback from the wider community on PEP 357. It is nearing the acceptance stage and has previously been discussed on python-dev. This is a chance for the wider Python community to comment on the proposal. You will find the PEP attached PEP: 357
2
6709
by: AWasilenko | last post by:
I'm trying to test a few different approaches to displaying pages via Cherrypy and I'm not having much luck. Here is my code so far: import sys, cherrypy, html class Root: @cherrypy.expose def index(self, pageid = None): selection = html.Page() return selection.input()
45
5253
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can multiple it by 1000 to get 11111 and the preform bitwise like <<2 to get 88888 and then divide by 1000 to go back to float 8.8888. but these seem...
0
1396
by: king kikapu | last post by:
Hi, i have a problem with the following piece of code that id just drive me nuts (from the morning...) I think is more Python specific than Qt, folks from Qt forum have already give me directions of how to do it but that Python error message is just impossible for me to figure out. And i am sure that it something just under my nose... ...
2
10983
by: mmiikkee13 | last post by:
>>a_list = range(37) .... print k, v .... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not iterable What 'int' object is this referring to? I'm iterating over a dict, not an int.
5
9812
by: cj007541 | last post by:
Hey. Im working on this for a school project thing and i need some help please. from Tkinter import* import random import time number = 5 i = 0
4
4072
by: arturo trafny | last post by:
I am getting the following error: ##this is the error message i receive Traceback (most recent call last): File "C:\Users\a\Desktop\checkerboard", line 26, in <module> print(checkerboard(plaintext)) File "C:\Users\a\Desktop\checkerboard", line 20, in checkerboard ciphertext=ciphertext+idx TypeError: Can't convert 'int' object...
0
7893
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7928
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8188
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5695
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5369
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3839
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.