Parameter Problem

This is the place for queries that don't fit in any of the other categories.

Parameter Problem

Can you help me spot the problem please
David

Code: Select all
`def input_data():    number = int(input("Please enter a number"))    return numberdef process_data(number):    divisible = False     if number //7 and number%7 < 0:        divisible = True        print("Number is divisible")    else:        print("Number is not divisible")    return divisibledef output_data(divisible):    print("Answer: {0}".format(divisible))def main():    number = input_data()    calculation = process_data(number)    output_data(answer)`
Last edited by micseydel on Sun Jun 09, 2013 8:15 am, edited 1 time in total.
Reason: Added code tags and locked OP.
daveozborne

Posts: 4
Joined: Sun Jun 09, 2013 8:03 am

Re: Parameter Problem

Some tips: do not post the same thing a second time. Use code tags. Do not include "help" in your title. Post in the right place (I'm about to move your post to a coding section of the forum).

The line
Code: Select all
`if number //7 and number%7 < 0:`

Probably does nothing like what you expect. Break down each part of that line, and look at what they are. If you're absolutely baffled, tell us what you think this does and what you want it to do.
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from

micseydel

Posts: 2799
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Parameter Problem

Hi
That was quick -
Outlined is the task trying to solve:

Write three functions:
inputData() - this function will input a number from the user and return it

processData(number) - this function will see if the number is divisible by 7 without a remainder and if it is it will return True otherwise false. Tip use the integer division // and the remainder % operators for this.

outputData(result) - this function will input the value from the previous function and print a user friendly message at the screen

main() - this function will input a number from the user
daveozborne

Posts: 4
Joined: Sun Jun 09, 2013 8:03 am

Re: Parameter Problem

Can you help me spot the problem please

If you run the code, you can spot the problem pretty quickly as you get a traceback
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam

metulburr

Posts: 2135
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Parameter Problem

Yes it said this...

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
main()
line 32, in main
NameError: global name 'answer' is not defined
>>>

meaning?
daveozborne

Posts: 4
Joined: Sun Jun 09, 2013 8:03 am

Re: Parameter Problem

That is a very clear traceback. You're using a variable which you have not defined. Look at the variable it's mentioning, and figure out what variable you have created that you meant to pass to the function (assuming there is one; otherwise you must create it).
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from

micseydel

Posts: 2799
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Parameter Problem

Cracked it - needed to take the calculation variable from the process data!!
daveozborne

Posts: 4
Joined: Sun Jun 09, 2013 8:03 am

Re: Parameter Problem

Cracked it - needed to take the calculation variable from the process data!!

I find it humerous that you stated you "cracked it", as the traceback stated the problem in the first place
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam

metulburr

Posts: 2135
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY