Need help with this exponent calculator code | Sololearn: Learn to code for FREE!

+3

Need help with this exponent calculator code

What my code is meant to do is print the powers of an integer that is being used as input ex) if I enter 5 as input it should print: base: 5 Exponent of 0: 1 Exponent of 1 : 5 Exponent of 2: 25 Exponent of 3: 125 and I think you can get the gist of it from here Here's the link to my code: https://code.sololearn.com/c3mDBu64z4qg/#py If someone can point out all the flaws of my code and how I can correct it that would be great, because I am still trying to adjust to Python's syntax after learning C++.

2/27/2017 2:41:56 PM

Christopher Carillo

1 Answer

New Answer

+8

line1: you didn't define the variable. So, there's no way further lines work lines 9-19: you should put them inside the while loop look the alternative way to your program made by myself (ps: I tried small values to test, modify at your purposes) CODE: while True: num = int(input("Number: ")) #you can use empty () as well if num == 0: break else: print("Base of", num) print("\n") exponent = 0 while exponent <= 5: result = num**exponent print("Exponent of ", exponent,":",result) exponent += 1 print("\n\n")