+ 4

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++.

27th Feb 2017, 2:41 PM
Christopher Carillo
Christopher Carillo - avatar
1 Odpowiedź
+ 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")
27th Feb 2017, 8:47 PM
LayB
LayB - avatar