调试代码以分配一个项目与另一个项目的总和



我是一名学生,这是我第一次使用Python,所以我遇到了一些小麻烦。我使用的电子工作簿Zybooks在解释(或缺乏解释(如何做它要求的事情方面做得很糟糕。整节课都没有讨论如何编写这种特定类型的代码。

它问。。。

编写一个语句,用nickel_count和dime_count的和来分配total_coins。100个镍币和200个一角硬币的样本输出为:

total_coins = 0
nickel_count = int(input())
dime_count = int(input())
print(total_coins)

我不知道从哪里开始。

我试过了:

print(nickel_count + dime_count)

我得到了正确的答案(300(,但它创建了一条只有零的第二行,因此它将其标记为错误。我只需要300本身。

3000

首先,我们需要使用您的代码并对其进行调整,以将total coins设置为数字(dime_count+nickel_count(。这很简单:

nickel_count = int(input())
dime_count = int(input())
total_coins = nickel_count + dime_count
print(total_coins)

此外,为了让挑战对象更清楚,请在input函数中添加提示。

nickel_count = int(input('How many nickels have you got? '))
dime_count = int(input('How many dimes have you got? '))
total_coins = nickel_count + dime_count
print(total_coins)

完成

最新更新