473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

help - python question

1
Please 'am a new beginnger in python. I have been trying to solve these problems, but 'am always getting stuck. Can you please help me out:

1.
Expand|Select|Wrap|Line Numbers
  1.  numBuckets = 8
  2. buckets = [0] * numBuckets
  3. bucketWidth = 1.0 / numBuckets
  4. for i in range(numBuckets):
  5.       low = i * bucketWidth
  6.       high = low + bucketWidth
  7.       buckets[i] = inBucket(list, low, high)
  8. print buckets

the output suppose to give me values, after running the program, I kept getting this:

Expand|Select|Wrap|Line Numbers
  1. >>>[none, none, none, none, none, none, none, none]
2.
Expand|Select|Wrap|Line Numbers
  1.  numBuckets = 8
  2. buckets = [0] * numBuckets
  3. for i in list:
  4.       index = int(i * numBuckets)
  5.       buckets[index] = buckets[index] + 1

I am using python 2.5.1 version
May 23 '07 #1
2 1391
bartonc
6,596 Expert 4TB
Please 'am a new beginnger in python. I have been trying to solve these problems, but 'am always getting stuck. Can you please help me out:

1.
Expand|Select|Wrap|Line Numbers
  1.  numBuckets = 8
  2. buckets = [0] * numBuckets
  3. bucketWidth = 1.0 / numBuckets
  4. for i in range(numBuckets):
  5.       low = i * bucketWidth
  6.       high = low + bucketWidth
  7.       buckets[i] = inBucket(list, low, high)
  8. print buckets

the output suppose to give me values, after running the program, I kept getting this:

Expand|Select|Wrap|Line Numbers
  1. >>>[none, none, none, none, none, none, none, none]
2.
Expand|Select|Wrap|Line Numbers
  1.  numBuckets = 8
  2. buckets = [0] * numBuckets
  3. for i in list:
  4.       index = int(i * numBuckets)
  5.       buckets[index] = buckets[index] + 1

I am using python 2.5.1 version
1: You'll need to include the inBucket function.
2: I'm not sure what you are trying to do, but this may give you some clues to both problems:
Expand|Select|Wrap|Line Numbers
  1. numBuckets = 8
  2. buckets = [0] * numBuckets
  3.  
  4. def ChangeBucketsInPlace():
  5.     for i in range(numBuckets):
  6.         index = int(i * numBuckets)
  7.         buckets[i] = index
  8.  
  9.  
  10. print buckets
  11. ChangeBucketsInPlace()
  12. print buckets
  13.  
May 23 '07 #2
I'm guessing your following the code from the site at How to Think Lika a Computer Scientist: Chapter 9. Post of the code, so we can see the values of the list and the definition of the inBucket function, there might be some typos or something like that
May 23 '07 #3

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

Similar topics

12
by: rhmd | last post by:
Just found Python and I love it. What an elegant language! I would like to use it for various applications, but the mathematical calculations are way too slow (a million sines 8 seconds in Python...
10
by: Jacek Generowicz | last post by:
Where can I find concise, clear documentation describing what one has to do in order to enable Python's internal help to be able to provide descriptions of Python keywords ? I am in a situation...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
0
by: Leeds, Mark | last post by:
This is a follow up question To the previous question About sorting that I sent for my friend. -----Original Message-----
3
by: frozenee | last post by:
I've noticed that the listings in help don't take you to correct topic. anyone else have this problem? Is there a fix?
2
by: yaffa | last post by:
dear python gurus, quick question on syntax. i have a line of code like this for incident in bs('tr', {'bgcolor' : '#eeeeee'}): what i want it to do is look for 'bgcolor' : '#eeeeee'...
5
by: jackinoob | last post by:
Hi All, Apologies in advance, this question is very rudimentary, but I can't seem to get it right. I am running python within cygwin. I have a python script called test.py, and inside it a...
6
by: idev | last post by:
Hi all, Please help me with my stuff. I downloaded python 2.5.1 package from http://blastwave.org it was compiled using Sun Studio 11 for Solaris 8 sparc. My system is Solaris 10 sparc and I...
0
by: Steve Holden | last post by:
Karthik Krishnan wrote: Apart from the syntax error Rob pointed out (use of "=" instead of "==" as a comparison operator) the output you show makes it seem possible you are entering the command...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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,...

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.