Python Forum
where to start with power program?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where to start with power program?
#11
(Oct-04-2017, 05:19 PM)nomoremrriceguy Wrote: I want to get the power of any number from 1-8 what would I put in the pow ( )? I was thinking x or str(x) or just something that is variable
x should be a integer,so then you need to convert input to int().
x is not a good name.
base_vaule = int(input("Enter Base Value: "))
Inside function a loop:
>>> base_value = 3
>>> for n in range(1, 9):
...     print(base_value ** n)
3
9
27
81
243
729
2187
6561
So base_value is outside function,you give it as a argument to the function my_pow(base_value):.
my_ is used so it don't overwrite build in pow().
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020