In python
Posted: Sun Jul 10, 2022 11:25 am
In python
Exercise 1: Recursive Power Function Create a program that takes in a base and exponent for the user. If the input is valid, it prints the answer of the base taken to the power given. You must require the user to give ints for both the base and the exponent. Also, the exponent must be zero or larger. Sample runs: Enter a base: 2 Enter a power: 3 Answer: 8 Enter a base: 256 Enter a power: 1 Answer: 256 Enter a base: 256 Enter a power: 0 Answer: 1 Enter a base: -1 Enter a power: 3 Answer: -1 Enter a base: 2 Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: 10 Answer: 1024
Exercise 1: Recursive Power Function Create a program that takes in a base and exponent for the user. If the input is valid, it prints the answer of the base taken to the power given. You must require the user to give ints for both the base and the exponent. Also, the exponent must be zero or larger. Sample runs: Enter a base: 2 Enter a power: 3 Answer: 8 Enter a base: 256 Enter a power: 1 Answer: 256 Enter a base: 256 Enter a power: 0 Answer: 1 Enter a base: -1 Enter a power: 3 Answer: -1 Enter a base: 2 Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: -1 Sorry, your exponent must be zero or larger. Enter a power: 10 Answer: 1024