我意识到这段代码真的没有意义,但我只是在练习:)。
基本上我想要做的是,如果用户输入生日的空白名称,我希望它跳转到储蓄循环并运行该代码。
我意识到以下情况并不正确:
self.savings()
有什么想法吗?
由于
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)
答案 0 :(得分:1)
而不是
中的self.savings()
if name == '':
self.savings()
你不能使用break
立即离开while循环吗?然后它应该继续下一个循环。
......我很确定这会奏效。