0
tries = 0
while tries < 4:
deposit = input("Enter amount to deposit: ")
try:
deposit = int(deposit)
if deposit < 0:
raise "invalid output"
except:
print("This transaction cannot proceed. You entered amount in negative")
tries += 1
else:
print("Deposited: \tPKR ", deposit)
print("Current Balance: \tPKR %d"%(currentBalance + deposit))
currentBalance += deposit
print("Would you like to do any more Transaction?")
answer = input("Enter Y for Yes and N for No: ")
try:
if answer.isalpha() == False:
raise "invalid output"
except:
print("Your input was considered as 'N'")
main()
print("You entered invalid input three times. Now open your account again")
main()
とforループの代わりにwhileループを使用することができますが、あなたは範囲(0,4)での試行のために 'みました:'代わりに? – doctorlove
コードのみの質問は...悪いです。 –
ようこそスタックオーバーフロー!私はあなたのコードを大幅に再フォーマットしました:同じコードの2つのインスタンスが重複しているように見えましたので、私はただ1つのインスタンスに置き換えました。あなたはforループとしてコードを書き直すことを求めていて、達成しようとしている最終目標は何ですか?コメントに示唆されたアイデアのいくつかを試して、あなたの試行であなたの質問を編集することができます。がんばろう! – Praveen