I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it:
def factorial(n):
a = n
b = n
while a>0 and b>1:
n = (n)*(b-1)
b = b-1
def perm(n, r):
a = factorial(n)
b = factorial(n-r)
q = a / b
print q
Then I went back to IDLE and input the following:
>>import mod mod.perm(5, 4)
I recieved the following error message:
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
mod.perm(5, 4)
File "C:\Python25\mo d.py", line 27, in perm
q = a / b
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
I have no idea how to fix it. I'm pretty new to Python. I have IDLE 1.2.2 and Python 2.5.2,
Please help. 2 8431
On May 1, 5:21*pm, "Jordan Harry" <jha...@EmeryWe iner.orgwrote:
I'm trying to write a simple program to calculate permutations. *I created a file called "mod.py" and put the following in it:
def factorial(n):
* * a = n
* * b = n
* * while a>0 and b>1:
* * * * n = (n)*(b-1)
* * * * b = b-1
def perm(n, r):
* * a = factorial(n)
* * b = factorial(n-r)
* * q = a / b
* * print q
Then I went back to IDLE and input the following:
>import mod mod.perm(5, 4)
I recieved the following error message:
Traceback (most recent call last):
* File "<pyshell#1 >", line 1, in <module>
* * mod.perm(5, 4)
* File "C:\Python25\mo d.py", line 27, in perm
* * q = a / b
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
I have no idea how to fix it. *I'm pretty new to Python. *I have IDLE 1.2.2 and Python 2.5.2,
Please help.
Your factorial function needs to return something.
~Sean
"Jordan Harry" <jh****@EmeryWe iner.orgwrites:
I'm trying to write a simple program to calculate permutations. I
created a file called "mod.py" and put the following in it:
def factorial(n):
a = n
b = n
while a>0 and b>1:
n = (n)*(b-1)
b = b-1
A function that does some calculations internally, but has no 'return'
statement and thus implicitly returns 'None'.
def perm(n, r):
a = factorial(n)
b = factorial(n-r)
These statements bind the 'None' returned by the 'factorial' function
to the names 'a' and 'b'.
q = a / b
This attempts to use the '/' operator on 'None' with 'None', which
raises the exception you saw.
(good sigmonster, have a cookie)
--
\ "Pinky, are you pondering what I'm pondering?" "I think so, |
`\ Brain, but Zero Mostel times anything will still give you Zero |
_o__) Mostel." -- _Pinky and The Brain_ |
Ben Finney This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Atul Kshirsagar |
last post by:
Hello,
I am using Python 2.3.2 with a C++ extention DLL in
muti-threaded environment.
1. For each new thread I create a separate
sub-interpreter.
2. Each thread executes multiple python statements
calling the class objects in my extention DLL.
3. Before each execution I import my extention module
using;
|
by: Martin Koekenberg |
last post by:
Hello,
Ik get the following error when I install a new Python software
package such as Zope or PIL.
This is what I get whem I 'make' Zope :
running build_ext
Traceback (most recent call last):
File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ?
|
by: gaudetteje |
last post by:
I just read in the 'What's New in Python 2.4' document that the None
data type was converted to a constant:
http://python.org/doc/2.4/whatsnew/node15.html
"""
# None is now a constant; code that binds a new value to the name
"None" is now a syntax error.
"""
So, what's the implications of this? I find the lack of explanation a
|
by: homepricemaps |
last post by:
if i do the following i get the url of an image i am looking for
image = ""
image = bs.img
print image
however if i do this
out.write (image )
i get an error that says "nonetype error is not callable"
|
by: John Allman |
last post by:
Hi all,
I'm trying to create a setup which allows a program to request an object
using strings and get an object of that type. It appears to be mostly
working but i have difficulties if i attempt to load a module at runtime
and then request an object of that type.
Essentially, my code works as follows:
I have a registry class which has a method to register a class. It
| |
by: thompson.marisa |
last post by:
Hi.
I'm extremely new to Python and programming as a whole. I have written
a python script with the assistance of ESRI ArcGIS 9.2, which uses
Python 2.4.1, however, it gives me this error when I try to run it.
I've already posted at ESRI support, and I was hoping that Python
people could help me more.
I hope there is something simple I could do to be able to define the
object that it thinks is NoneType. Please when someone responds,
|
by: tom |
last post by:
Hi!
My code is
And it gives following error:
How can sortedList variable turn into NoneType? I just don't get it...
|
by: Gabriel Genellina |
last post by:
En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma.saeedi@gmail.comescribió:
NoneType is not an exception, but the type of the None object. Perhaps you're not interpreting correctly some error messages:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
(the exception raised is a TypeError; NoneType is part of the message).
|
by: ssecorp |
last post by:
Im looking into PvsNP:
http://www.claymath.org/millennium/P_vs_NP/
so I thought I'd write the program just to get a feel for it.
But I run into a problem. Why does it all the sudden return None? I
mean I know why the program aborts but I dont understand why the None
is generated all the sudden. Hitting recursion depth isn't reported
with that error.
Guess I am missing something very obvious.
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |