Jump to content

I need help in python!

whengtotsz
Verify_ISBN_10 = 1Exit = 2def main():    choice = 0    while choice != Exit:        display_menu()        choice = int(input('Please enter a number in the main MENU: '))        if choice == Verify_ISBN_10:                     radius = float(input('Enter the 9 digit numbers for the ISBN: '))                     print('Your check digit is: ', ISBN_10)        elif choice == Exit:                     print('Exit the program!')        else:            print('Invalid choice..')def ISBN_10(ISBN10):    while len(ISBN10) != 9:        print('Please enter a valid 9 digit.')        ISBN10=int(input('Please enter the 9 digit number: '))        continue    else:        D1 = int(ISBN10[0])*1        D2 = int(ISBN10[1])*2        D3 = int(ISBN10[2])*3        D4 = int(ISBN10[3])*4        D5 = int(ISBN10[4])*5        D6 = int(ISBN10[5])*6        D7 = int(ISBN10[6])*7        D8 = int(ISBN10[7])*8        D9 = int(ISBN10[8])*9        Sum=(D1+D2+D3+D4+D5+D6+D7+D8+D9)        Mod=Sum%11        print('Your check digit is: ', Mod)def display_menu():    print('                 MENU')    print('1) Verify the check digit of an ISBN-10')    print('2) Exit')main()             

I need help in python because I keep getting this check digit answer whenever I run it.

Please enter a number in the main MENU: 1Enter the 9 digit numbers for the ISBN: 013149498Your check digit is:  <function ISBN_10 at 0x019870C0>
Link to comment
Share on other sites

Link to post
Share on other sites

Verify_ISBN_10 = 1Exit = 2def main():    choice = 0    while choice != Exit:        display_menu()        choice = int(input('Please enter a number in the main MENU: '))        if choice == Verify_ISBN_10:                     radius = float(input('Enter the 9 digit numbers for the ISBN: '))                     print('Your check digit is: ', ISBN_10)        elif choice == Exit:                     print('Exit the program!')        else:            print('Invalid choice..')def ISBN_10(ISBN10):    while len(ISBN10) != 9:        print('Please enter a valid 9 digit.')        ISBN10=int(input('Please enter the 9 digit number: '))        continue    else:        D1 = int(ISBN10[0])*1        D2 = int(ISBN10[1])*2        D3 = int(ISBN10[2])*3        D4 = int(ISBN10[3])*4        D5 = int(ISBN10[4])*5        D6 = int(ISBN10[5])*6        D7 = int(ISBN10[6])*7        D8 = int(ISBN10[7])*8        D9 = int(ISBN10[8])*9        Sum=(D1+D2+D3+D4+D5+D6+D7+D8+D9)        Mod=Sum%11        print('Your check digit is: ', Mod)def display_menu():    print('                 MENU')    print('1) Verify the check digit of an ISBN-10')    print('2) Exit')main()             

I need help in python because I keep getting this check digit answer whenever I run it.

Please enter a number in the main MENU: 1Enter the 9 digit numbers for the ISBN: 013149498Your check digit is:  <function ISBN_10 at 0x019870C0>

 

Looks like you forgot the parentheses after the function call:

 

print('Your check digit is: ', ISBN_10)

 

Should be:

 

print('Your check digit is: ', ISBN_10())

 

The function you defined also takes one parameter, so don't forget that either.

Link to comment
Share on other sites

Link to post
Share on other sites

Looks like you forgot the parentheses after the function call:

 

print('Your check digit is: ', ISBN_10)

 

Should be:

 

print('Your check digit is: ', ISBN_10())

 

The function you defined also takes one parameter, so don't forget that either.

should I put a global variable for ISBN_10? Whenever I do ISBN_10()) it gives me these:

Traceback (most recent call last):  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 86, in <module>    main()  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 16, in main    print('Your check digit is: ', ISBN_10())TypeError: ISBN_10() missing 1 required positional argument: 'ISBN10'
Link to comment
Share on other sites

Link to post
Share on other sites

Verify_ISBN_10 = 1Exit = 2def main():    choice = 0    while choice != Exit:        display_menu()        choice = int(input('Please enter a number in the main MENU: '))        if choice == Verify_ISBN_10:                     radius = float(input('Enter the 9 digit numbers for the ISBN: '))                     print('Your check digit is: ', ISBN_10)        elif choice == Exit:                     print('Exit the program!')        else:            print('Invalid choice..')def ISBN_10(ISBN10):    while len(ISBN10) != 9:        print('Please enter a valid 9 digit.')        ISBN10=int(input('Please enter the 9 digit number: '))        continue    else:        D1 = int(ISBN10[0])*1        D2 = int(ISBN10[1])*2        D3 = int(ISBN10[2])*3        D4 = int(ISBN10[3])*4        D5 = int(ISBN10[4])*5        D6 = int(ISBN10[5])*6        D7 = int(ISBN10[6])*7        D8 = int(ISBN10[7])*8        D9 = int(ISBN10[8])*9        Sum=(D1+D2+D3+D4+D5+D6+D7+D8+D9)        Mod=Sum%11        print('Your check digit is: ', Mod)def display_menu():    print('                 MENU')    print('1) Verify the check digit of an ISBN-10')    print('2) Exit')main()             

I need help in python because I keep getting this check digit answer whenever I run it.

Please enter a number in the main MENU: 1Enter the 9 digit numbers for the ISBN: 013149498Your check digit is:  <function ISBN_10 at 0x019870C0>

You aren't calling the function. In your main method, if the selection equals Verify_ISBN_10, call the function ISBN_10.

 

You want to replace: 

print('Your check digit is: ', ISBN_10)

 

with 

 

ISBN_10(radius)

 

And it looks like you want to change the float cast to int on the line before it.

Link to comment
Share on other sites

Link to post
Share on other sites

 

should I put a global variable for ISBN_10? Whenever I do ISBN_10()) it gives me these:

Traceback (most recent call last):  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 86, in <module>    main()  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 16, in main    print('Your check digit is: ', ISBN_10())TypeError: ISBN_10() missing 1 required positional argument: 'ISBN10'

 

As I just said, you need to feed 1 variable to the function when you call it, because you've defined your function to take 1 parameter.

 

Since you have your function definition like this:

 

def ISBN_10(some_variable):

 

Your function calls need to pass it one variable, like this: ISBN(variable), not just with blank parentheses.

Link to comment
Share on other sites

Link to post
Share on other sites

now it gives me this sir, I am so lost right now. 

Traceback (most recent call last):  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 86, in <module>    main()  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 16, in main    print('Your check digit is: ', ISBN_10(radius))  File "C:/Users/whengtotsz/Desktop/Python Final Attemp/MENU for the ISBN.py", line 33, in ISBN_10    while len(ISBN10) != 9:TypeError: object of type 'int' has no len()
Link to comment
Share on other sites

Link to post
Share on other sites

anyone know how to fix this? :(

while len(ISBN10)!= 9:TypeError: object of type 'int' has no len() 

Im just new from this program so please bear with me. :\

Link to comment
Share on other sites

Link to post
Share on other sites

anyone know how to fix this? :(

while len(ISBN10)!= 9:TypeError: object of type 'int' has no len() 

Im just new from this program so please bear with me. :\

Oh. Your parameter assumes a string. You can remove the cast from radius:

radius = input('Enter the 9 digit numbers for the ISBN: ')

Link to comment
Share on other sites

Link to post
Share on other sites

Oh. Your parameter assumes a string. You can remove the cast from radius:

radius = input('Enter the 9 digit numbers for the ISBN: ')

You're a life saver!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×