![]() |
Need help with my program - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help with my program (/thread-23031.html) |
Need help with my program - zeclipse21 - Dec-08-2019 This is supposed to be the outcome of my code my code isn,exp=int(input("Enter the value of the base:")).split(",") def power(n,exp): if(exp==1): return(n) if(exp!=1): return(n*power(n,exp-1)) print("The power of",n, "raised to",exp,"is",power(n,exp))This is the error i receive
RE: Need help with my program - ibreeden - Dec-08-2019 If you have such an error in a compound statement, you must split it to see where exactly the error arises. The message tells you the error is in: n,exp=int(input("Enter the value of the base:")).split(",")The first part to be executed will be: input("Enter the value of the base:")When you enter the string: '3,5', this will be replaced with '3,5' in the next stage: >>> int('3,5') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '3,5'This gives you the answer: '3,5' is not an integer. int() expects one parameter, so the most readable construction would be to split the line into:n,exp=input("Enter the value of the base:").split(",") n = int(n) exp = int(exp)The most |