申し訳ありませんが、これは複雑ではないようですが、私はPythonを初めて使用しています。辞書を使って条件を作成するにはどうすればいいですか?
子供のスコアが100以上であれば、プレゼントは8点あります。子供のスコアが50〜100の場合は5つのプレゼントを、子供のスコアが50未満の場合は2つのプレゼントを得る。
辞書を使用してユーザーの入力が正しいかどうかを確認するにはどうすればよいですか?尋ねた質問に関連
presents=[]
People={"Dan":22,
"Matt":54,
"Harry":78,
"Bob":91}
def displayMenu():
print("1. Add presents")
print("2. Quit")
choice = int(input("Enter your choice : "))
while 2< choice or choice< 1:
choice = int(input("Invalid. Re-enter your choice: "))
return choice
def addpresents():
name= input('Enter child for their score: ')
if name == "matt".title():
print(People["Matt"])
if name == "dan".title():
print(People["Dan"])
if name == "harry".title():
print(People["Harry"])
if name == "bob".title():
print(People["Bob"])
present=input('Enter number of presents you would like to add: ')
if present
#This is where I got stuck
option = displayMenu()
while option != 3:
if option == 1:
addpresents()
elif option == 2:
print("Program terminating")
option = displayMenu()
を質問は何ですか? – fedepad
「プレゼント」とは何ですか?子供に贈りたいプレゼントの数ですか?もしそうなら、それを与えるためにプレゼントの量をあらかじめ定義しておけばそれはなぜですか? –
あなたが求めていることはあまり明確ではありません。あなたの質問をもう一度見て、あなたが問題を抱えていることを正確に再確認しようとしてください。 –