I realize this code really makes no sense, but I am just practicing :)
Basically want I want to do is if the user enters a blank name for birthdays, I want it to jump to the savings loop and run through that code.
I am realizing though that the following is not correct:
self.savings()
Any ideas?
Thanks
birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}
while True:
print('Enter a name: (blank to quit)')
name = input()
if name == '':
self.savings()
if name in birthdays:
print(birthdays[name] + ' is the birthday of ' + name)
else:
print('I do not have birthday information for ' + name)
print('What is their birthday?')
bday = input()
birthdays[name] = bday
print('Birthday database is updated')
savings = {'401k': '100.00', 'RothIRA': '500.00', 'Savings': '350.00'}
while True:
print('Enter an account: (blank to quit)')
money = input()
if money =='':
break
if money in savings:
print((savings[money] + ' is the total amount in your ') + money)
else:
print('I do not have savings info for ' + money)
print('How much money is in this account?')
acct = input()
savings[money] = acct
print('Savings database is updated')
print(savings)
asked Jul 21, 2017 at 2:48
JD2775
3,8418 gold badges38 silver badges69 bronze badges
-
1Your question is unclear. Your code doesn't define any functions or methods. I think you need to read about defining functions in your textbook or tutorial.PM 2Ring– PM 2Ring2017年07月21日 02:53:14 +00:00Commented Jul 21, 2017 at 2:53
-
Use definitions?Santiago Benoit– Santiago Benoit2017年07月21日 02:53:29 +00:00Commented Jul 21, 2017 at 2:53
-
@PM2Ring you are correct, I don't actually have any functions or methods. Just 2 dictionary variables. I wasn't looking at this clearly. ThanksJD2775– JD27752017年07月21日 02:58:47 +00:00Commented Jul 21, 2017 at 2:58
1 Answer 1
Instead of self.savings() in
if name == '':
self.savings()
couldn't you you use break to leave the while loop immediately? And then it should move on to the next loop.
...I'm pretty sure that would work.
Sign up to request clarification or add additional context in comments.
Comments
lang-py