- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于我之前提出的问题,我深表歉意,因为这些问题含糊不清且难以回答。我对编程还很陌生,并且仍在学习它的来龙去脉。所以请耐心听我说。现在介绍背景信息。我正在使用 python 3.3.0。我已将其加载到 Eclipse IDE 中,这就是我用来编写代码并进行测试的地方。
现在回答问题:我正在尝试学习如何创建和使用字典。因此,我的任务是创建一个价格匹配代码,该代码通过用户界面不仅能够在字典中搜索项目(即键以及与键关联的值的位置和价格)。我已经创建了一个用户界面,它将运行得足够好,不会出现任何错误(至少在 IDE 中),当我运行并输入所有提示时,空字典不会更新,因此我无法调用早期输入的字典。
我有到目前为止在下面编写的代码,希望有人能告诉我我是否正确地做事。如果有更好的方法来解决这个问题。我仍在学习,因此有关代码术语的更详细解释会很有用。
print("let's Price match")
decition = input("Are you adding to the price match list?")
if decition == "yes":
pricematchlist = {"Snapple":["Tops",99]}
location = input("Now tell me where you shopped")
item = input("Now what was the item")
price = input("Now how much was the item")
int(price)
pricematchlist[item]=location,price
print(pricematchlist)
else:
pricematchlist = {"Snapple":["Tops",99]}
reply = input("Ok so you want to search up a previous price?")
if reply == "yes":
search = input("What was the item?")
pricematchlist.item(search)
最佳答案
这些是一些细微的变化。对于字典:您正确使用它们。
print("let's Price match")
pricemathlist = {"Snapple":["Tops", 99]} # assign it here
decition = input("Are you adding to the price match list?").lower() #"Yes"-->"yes"
if decition == "yes":
# pricematchlist = {"Snapple":["Tops",99]}
# If this whole code block is called repeatedly, you don't want to reassign it
location = input("Now tell me where you shopped")
item = input("Now what was the item")
price = int(input("Now how much was the item"))
# int(price) does nothing with reassigning price
pricematchlist[item]=location,price
print(pricematchlist)
else:
reply = input("Ok so you want to search up a previous price?").lower()
if reply == "yes":
search = input("What was the item?")
print pricematchlist[search] # easier way of accessing a value
关于python - 使用字典,练习代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15852757/
K&R 前。 4.2 要求您修改给定的(非标准)atof 函数,该函数缺少处理指数的指数处理机制(如 123e6 或 456e-7)。我添加了一个最小的更改来处理正确输入的、无空格的个位数指数。为了检
我正在学习计算机科学入门类(class)的考试,我对“常规”算法和递归算法中的复杂性主题有疑问(通常我们将这些问题写成 C 代码). 我想知道 Internet 和/或书籍中是否有涵盖该主题的基础级别
console.log( ‘blah’.repeatMe( 3 ) ); 使用 Javascript 编写代码,使前面的函数打印: 输出:blahblahblah 最佳答案 噢,放弃函数式解决方案太有
我正在准备 Java SE 7 认证考试,并且正在做一些关于继承和访问修饰符的无聊练习。 但是现在我在应用继承时遇到了意外的行为。在我的基础包 com.testpkg 中,我有一个抽象类: packa
我刚刚开始了 C 语言队列的第一课,我得到了创建队列、向队列添加元素和删除元素的练习。但是,我在检查队列是满还是空时遇到了麻烦。 #include typedef struct FloatQueue
请问我从昨天开始就被困在下面这个问题中了。下面是问题: Write a program that uses console.log to print all the numbers from 1 to
我最近尝试了一些 Java,希望对我的风格进行一些评论。如果你喜欢看这个放在图像中的练习,并告诉我我的风格是否足够好?或者是做的还不够好,可以告诉我应该在哪方面多下工夫,帮我改进一下? exercis
我对手动编写 SQL 查询还很陌生,而且我有一个我似乎无法解决的练习。 我了解解决此问题所需的工具,但我就是想不出解决方案。 你能帮助我理解如何以一种能让我在未来解决类似练习的方式解决这个问题吗? 我
好吧,这就是练习: Define a class named student, containing three grades of students. The class will have a f
我是一个 JS 菜鸟,试图制作这个“你好,先生/小姐 你的名字!”干净的。我看不到在 if/else 中重构警报的方法,因为那样我就失去了 var b 的值。 JS: "use strict
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
反转二维数组的值,可以扩展 n 次。 [1, [2, [3, ... [n, null]]]] 给定: 所有数组的长度始终为 2 列表中的最后一个数组将包含一个 null 索引 1 示例: [1, [
我试图通过 Jason Hickey 笔记自学 OCaml,下面的练习让我难住了。 问题:编写一个函数 sum 给定两个整数边界 m,n 和函数 f 计算求和。 我正在尝试这个: let r
这是一个生成斐波那契数列的程序,这里是引用:http://sicp.org.ua/sicp/Exercise1-19 据说我们可以将程序视为“a <- bq + aq + ap and b <- bp
所以,我正在努力通过 SICP。 第 4 章的第一个练习是: Exercise 4.1. Notice that we cannot tell whether the metacircular eva
这个问题已经有答案了: Count the number of occurrences of a character in a string in Javascript (39 个回答) 已关闭 6
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我目前正在学习 JS,并且正在尝试进行编码练习。到目前为止,我已经成功地使用离线和在线部分代码的大量资源拼凑了以下代码。我已经非常接近了 - 只是结果中的数字无法正确。 一些背景:在函数中输入一个对象
我需要创建一个回收器 View 练习,这是一个带有简单的单个回收器的应用程序加载大小为 20 的页面,并且可以容纳无限数量的项目。 现在我不想做出重新加载越来越多的项目的幼稚解决方案,而是一个优雅的解
下面的实现正确吗? 输入:Oldrecords(GameRecord 对象数组)和 newRecords (GameRecord) 我将检查 oldRecords 数组中的 newRecord 值。如
我是一名优秀的程序员,十分优秀!