Untitled
unknown
plain_text
a year ago
952 B
3
Indexable
import numpy as np def double_money_numpy(starting_amount, days): # Generate an array representing each day days_array = np.arange(1, days + 1) # Calculate the amount for each day using exponential growth (2^x) amount = starting_amount * 2 ** (days_array - 1) # Print the results for day, money in zip(days_array, amount): print(f"Day {day}: ${money:.2f}") # Get user input for the starting amount and the number of days try: starting_amount = float(input("Enter the starting amount: $")) if starting_amount <= 0: raise ValueError("Starting amount should be greater than 0.") num_days = int(input("Enter the number of days: ")) if num_days < 1: raise ValueError("Number of days should be greater than or equal to 1.") # Call the function to double the money each day using NumPy double_money_numpy(starting_amount, num_days) except ValueError as e: print(f"Error: {e}")
Editor is loading...
Leave a Comment