Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions lm3226/assignment8.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,42 @@ def validate_denominations_input(denominations):
raise InvalidUserInputException("Invalid input.")

def main():
while True:
try:
user_input = input('''Suppose that you want to invest $1000.
You can purchase it in $1, $10, $100, $1000 denominations. Please
enter a list of denominations without dollar sign that you want to
purchase and separate each denomination by a comma,
such as 1,10,100,1000: '''
)
input_denominations = np.fromstring(user_input, dtype=int, sep=',')
validate_denominations_input(input_denominations)
except (ValueError, InvalidUserInputException) as e:
print('Invalid input. Please try again: ')
continue
else:
while True:
try:
user_num_input = input('Choose the number of times you want to invest: ')
user_num_trials = int(user_num_input)
if user_num_trials <= 0:
raise InvalidUserInputException
except (ValueError, InvalidUserInputException) as e:
print('Invalid input. Please try again: ')
continue
else:
user_invsetment = daily_investment_return(input_denominations, user_num_trials)
user_invsetment.generate_results()
try:
while True:
try:
user_input = input('''Suppose that you want to invest $1000.
You can purchase it in $1, $10, $100, $1000 denominations.
Please enter a list of denominations without dollar sign that
you want to purchase and separate each denomination by a comma,
such as 1,10,100,1000: '''
)
input_denominations = np.fromstring(user_input, dtype=int, sep=',')
validate_denominations_input(input_denominations)
except (ValueError, InvalidUserInputException) as e:
print('Invalid input. Please try again: ')
continue
else:
while True:
try:
user_num_input = input('Choose the number of times you want to invest: ')
user_num_trials = int(user_num_input)
if user_num_trials <= 0:
raise InvalidUserInputException
except (ValueError, InvalidUserInputException) as e:
print('Invalid input. Please try again: ')
continue
else:
user_invsetment = daily_investment_return(input_denominations, user_num_trials)
user_invsetment.generate_results()

print('Now generating example results with denominations of [1,10,100,1000] and 10000 trials')
example_investment = daily_investment_return([1,10,100,1000], 1000)
example_investment.generate_results()
break
break
print('Now generating example results with denominations of [1,10,100,1000] and 10000 trials')
example_investment = daily_investment_return([1,10,100,1000], 1000)
example_investment.generate_results()
break
break

except (KeyboardInterrupt, EOFError) as e:
sys.exit(0)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion lm3226/daily_investment_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def generate_histograms(self, trials):
self.make_denomination_histogram(trials[i], self.denominations[i])

def write_results_to_file(self, trials):
#Write mean as well as standard deviation to a file and save it into text
#Write mean as well as standard deviation to a file and save it into txt
f = open('results.txt', 'w')
for i in range(0, len(self.denominations)):
denomination = self.denominations[i]
Expand Down