0

言語をよりよく学ぶために、Pythonでプログラムを作成しています。

現在、私は2つの空の辞書を持っています。1つはとという名前bankAccountですpinCodebankAccountraw_inputとinputからキーと値を取得しますが、の場合pinCode、辞書からraw_inputを取得し、それを辞書bankAccountのPINのキーとして使用しますpinCode。どうやってやるの?

コードを普遍的にしたいので、他の人が情報を入力しても同じことが起こるので、使用できませんd[dictkey]

bankAccount = {} 
pinCode = {} 
bankAccount[raw_input("And what is your name?")] = input("Hello and welcome to MyBank, can I take your bank account number, please?") 
pinCode[] = input("Can we have your PIN code, please?")
4

1 に答える 1

2

If you're getting input from the user that you need to use more than once (as a key for both of your dictionaries), you'll need to save the value in a variable. It might not be a bad idea to do this for the other input values too, but that's not strictly required. Something like this will work:

name = raw_input("What is your name?")
acct = input("What is your account number?")
pin = input("What is your PIN?")

bankAccount[name] = acct
pinCode[name] = pin

I'm not sure what you mean by your final paragraph about the code being universal. You'll need to clarify that part if you still need help with it.

于 2013-01-07T22:20:28.643 に答える