gpt4 book ai didi

python - Dictionary_in_python 选择一个项目

转载 作者:行者123 更新时间:2023-12-01 09:07:36 25 4
gpt4 key购买 nike

我正在做以下字典:

import random

from tkinter.messagebox import YES

name = input("Hello, what is your name? ")
print("nice to meet you {}!".format(name))

instruments = (["Bass","Guitar","Piano"])

instruments1 = ({"Name":"Bass","Price":"US$ 900,00"},
{"Name":"Piano","Price":"US$ 1000,00"},
{"Name":"Guitar","Price":"US$ 900,00"})

print("{} we have these instruments for you to buy:".format(name),", ".join(instruments))
#the line above give m all items without the brackets

answer = input("You're going to take some of them? Yes or no.")#waiting the user input

if answer == YES:#boolean command for confirming the yes/no answer.

print("{} which one will be?".format(name))
pos_awnser = input()
print(pos_awnser,"It's a very good choice.")

elif awnser != YES:
print("Sorry, we don't have what you need.")
print(pos_awnser,"costs",)

我想显示之前选择的工具类型,并在控制台显示名称和价格

最佳答案

不要这样做,而是创建一个字典,就像这样

instruments = ({"Bass":'US$ 900,00',"Guitar":"US$ 1000,00","Piano":"US$ 900,00" })

然后您可以使用打印仪器,

print("{} we have these instruments for you to buy:".format(name),", ".join(instruments.keys())

并通过显示仪器类型

print(pos_awnser, instruments[pos_answer], " is a very good choice.")

关于python - Dictionary_in_python 选择一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51920736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com