repl.it
@katiewinton/

Dictionaries

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# bankAccount = {'123':12, '456':17.40}
# bankAccount['12345'] = 4294.99
# userInput=input('Type in your bank account number: ')
# # toDisplay = bankAccount[userInput]
# toDisplay = bankAccount.get(userInput,0)
# print('$'+str(toDisplay))

# # if toDisplay != None:
# #   print(toDisplay)
# # else:
# #   print('Your bank account does not exist.')

# # try:
# #   toDisplay = bankAccount[userInput]
# #   print(toDisplay)
# # except KeyError:
# #   print('Your bank account does not exist.')

bankAccounts = {'123':3000, '234':100, '345': 2, '456': 40}
number = input('What is your bank account number? ')
try:
  balance = bankAccounts[number]
except KeyError:
  keyError = True
  number = input('The number you entered does not seem to be a valid account. Please type in your account number again: ')
  while keyError == True:
    try:
      balance = bankAccounts[number]
      keyError = False
    except KeyError:
      keyError = True
      number = input('The number you entered does not seem to be a valid account. Please type in your account number again: ')
subtract = int(input('Your current balance is $' + str(balance) + '. How much would you like to subtract from your bank account? '))
if subtract<=balance:
  bankAccounts[number]=balance-subtract
  print('Your new balance is $'+str(bankAccounts[number]))
else:
  print('You do not have enough in your account to take out the amount you entered.')
?