第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

密碼庫問題,代碼不遵循 if 語句

密碼庫問題,代碼不遵循 if 語句

qq_笑_17 2021-12-29 20:05:04
我的程序是為了分配一個(gè)密碼庫,所以用戶創(chuàng)建一個(gè)帳戶并輸入密碼庫,然后他添加應(yīng)用程序和密碼并查看它,問題是它也必須打印摘要但是當(dāng)用戶沒有輸入的應(yīng)用程序和密碼它不告訴他們他們沒有任何。摘要代碼>>def app_summary():    while True:        if len(vault_apps) < 1:            print('''there is no summary of your acount as, you currently have 0 apps and passwords stored on your account''')          else: print('''You have {} app and its information stored'''.format(len(vault_apps)))        print('''Your longest password  is charecters''', max(len(a) for a in vault_apps))        print('''Your shortest password  is charecters''', min(len(a) for a in vault_apps))        goback_menu()        break 正如您所看到的,如果存儲(chǔ)了 < 一個(gè)應(yīng)用程序,它應(yīng)該打印出來,('''there is no summary of your acount as, you currently have 0 apps and passwords stored on your account''')但我收到了這個(gè)錯(cuò)誤: max(len(a) for a in vault_apps))builtins.ValueError: max() arg is an empty sequence
查看完整描述

2 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊

else:塊的縮進(jìn)不對(duì),應(yīng)該是:


else: 

    print('''You have {} app and its information stored'''.format(len(vault_apps)))

    print('''Your longest password  is charecters''', max(len(a) for a in vault_apps))

    print('''Your shortest password  is charecters''', min(len(a) for a in vault_apps))

作為一般規(guī)則,您可以避免將else:塊放在同一行上,這樣可以避免在之后向它們添加行時(shí)出現(xiàn)此類問題。


查看完整回答
反對(duì) 回復(fù) 2021-12-29
?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

你的縮進(jìn)是錯(cuò)誤的。你所有的print調(diào)用都應(yīng)該在else塊中。此外,請(qǐng)考慮使用f-strings并將長(zhǎng)度的生成器表達(dá)式分解為單獨(dú)的list:


if not vault_apps:

    print('There is no summary of your account as you have no apps and passwords stored.')  


else: 

    lengths = [len(a) for a in vault_apps]

    print(f'You have {n_apps} apps and their information stored.')

    print(f'Your longest password is {max(lengths)} characters.')

    print(f'Your shortest password is {min(lengths)} characters.')


查看完整回答
反對(duì) 回復(fù) 2021-12-29
  • 2 回答
  • 0 關(guān)注
  • 183 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)