作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做以下字典:
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/
我正在做以下字典: import random from tkinter.messagebox import YES name = input("Hello, what is your name? "
我是一名优秀的程序员,十分优秀!