Answer:
The recursion function is as follows:
def raise_to_power(num, power):
if power == 0:
return 1
elif power == 1:
return num
else:
return (num*raise_to_power(num, power-1))
Explanation:
This defines the function
def raise_to_power(num, power):
If power is 0, this returns 1
if power == 0:
return 1
If power is 1, this returns num
elif power == 1:
return num
If otherwise, it calculates the power recursively
else:
return (num*raise_to_power(num, power-1))
Solution:
initial = float(eval(input('Enter the monthly saving amount: ')))
x = (1 + 0.00417)
month_one = initial * x
month_two = (initial + month_one) * x
month_three = (initial + month_two) * x
month_four = (initial + month_three) * x
month_five = (initial + month_four) * x
month_six = (initial + month_five) * x
print('The sixth month value is: '+str(month_six))
Don't forget the saving amount, and initialize the balance with that amount. Inside the loop, work out and add the interest and then add the saving amount for the next month.
balance = 801
for month in range(6):
balance = balance * (1.00417)
print(balance)
Here is a somewhat cryptic solution that works:
#include <algorithm>
#include <cstdlib>
using namespace std;
void q(char c, int count)
{
for (int i = 0; i < count; i++) {
putchar(c);
}
}
void p(int b1, int plusses)
{
q(' ', b1);
q('+', plusses);
}
int main()
{
for (int i = -3; i <= 3; i++)
{
int pl = min(6, (3 - abs(i)) * 2 + 1);
p(6-pl, pl);
i == 0 ? p(0, 6) : p(6, 0);
p(0, pl);
putchar('\n');
}
getchar();
}
Answer:
def leap_year(y):
if y % 4 == 0:
return 1
else:
return 0
def number_of_days(m,y):
if m == 2:
return 28 + leap_year(y)
elif m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m ==10 or m == 12:
return 31
elif m == 4 or m == 6 or m == 9 or m == 11:
return 30
def days(m,d):
if m == 1:
return 0 + d
if m == 2:
return 31 + d
if m == 3:
return 59 + d
if m == 4:
return 90 + d
if m == 5:
return 120 + d
if m == 6:
return 151 + d
if m == 7:
return 181 + d
if m == 8:
return 212 + d
if m == 9:
return 243 + d
if m == 10:
return 273 + d
if m == 11:
return 304 + d
if m == 12:
return 334 + d
def days_left(d,m,y):
if days(m,d) <= 60:
return 365 - days(m,d) + leap_year(y)
else:
return 365 - days(m,d)
print("Please enter a date")
day=int(input("Day: "))
month=int(input("Month: "))
year=int(input("Year: "))
choice=int(input("Menu:\n1) Calculate the number of days in the given month.\n2) Calculate the number of days left in the given year.\n"))
if choice == 1:
print(number_of_days(month, year))
if choice == 2:
print(days_left(day,month,year))
Explanation:
Hoped this helped
Wiki is a web application that allows users to easily add and edit content on a web page.