Parameter Problem

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

Parameter Problem

Postby daveozborne » Sun Jun 09, 2013 8:09 am

Can you help me spot the problem please
David

Code: Select all
def input_data():
    number = int(input("Please enter a number"))
    return number

def 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 divisible

def 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

Postby micseydel » Sun Jun 09, 2013 8:18 am

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!
User avatar
micseydel
 
Posts: 1132
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Parameter Problem

Postby daveozborne » Sun Jun 09, 2013 8:24 am

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

Task posted:
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

Postby metulburr » Sun Jun 09, 2013 8:33 am

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
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1331
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Parameter Problem

Postby daveozborne » Sun Jun 09, 2013 8:43 am

Yes it said this...

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

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

Re: Parameter Problem

Postby micseydel » Sun Jun 09, 2013 8:47 am

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!
User avatar
micseydel
 
Posts: 1132
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Parameter Problem

Postby daveozborne » Sun Jun 09, 2013 9:25 am

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

Postby metulburr » Sun Jun 09, 2013 9:48 am

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
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1331
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests