コード例 #1
0
class PiggyATM():

	def __init__(self):
		self.bank = PiggyBank()

	def interact(self):
		while True:
			selection = int(input("""What would you like to do (Press corresponding number):
										   1.) Create an Account 
										   2.) Deposit 
										   3.) Withdraw 
										   4.) Transfer
										   5.) View Balance

										   -> """))
			
			if selection == 0:
				break
			elif selection > 5:
				print ("""\n## Response ##\n""")
				print ("Not a valid selection.\n")
				continue
			elif selection == 1:
				print ("""\n## Interact ##\n""")
				try:
					name = str(input("Enter your first and last names (case-sensitive with one space in between): "))
					pin = int(input("Enter a 4 digit pin to be associated with your account: "))
					print ("""\n## Response ##\n""")
					assert len(str(pin)) == 4
					assert len(name.split()) == 2
					self.bank.handle_account_creation(name, pin)
				except:
					print ("One or both of your entries was in an invalid format.")
					continue
			else:
				print ("""\n## Interact ##\n""")
				try:
					name = str(input("Enter your first and last names (case-sensitive with one space in between): "))
					pin = int(input("Enter the pin associated with your account: "))
					assert len(str(pin)) == 4
					assert len(name.split()) == 2
					if selection == 2:
						amount = float(input("Enter the amount to be deposited (To at least 1 decimal place): "))
						print ("""\n## Response ##\n""")
						self.bank.handle_deposit(name, pin, amount)
					elif selection == 3:
						amount = float(input("Enter the amount to be withdrawn (To at least 1 decimal place):: "))
						print ("""\n## Response ##\n""")
						self.bank.handle_withdraw(name, pin, amount)
					elif selection == 4:
						recipient = str(input("Enter the name of the transfer recipient (case-sensitive): "))
						amount = float(input("Enter the amount to be transferred (To at least 1 decimal place):: "))
						print ("""\n## Response ##\n""")
						self.bank.handle_transfer(name, pin, recipient, amount)
					elif selection == 5:
						print ("""\n## Response ##\n""")
						self.bank.show_balance(name, pin)
				except:
					print ("One or all of your entries was in an invalid format.")
					continue
コード例 #2
0
	def __init__(self):
		self.bank = PiggyBank()