当我找不到为什么它不允许它时,它不断给我语法错误消息

时间:2018-03-22 12:44:19

标签: python-3.x

当我出现这个任务的时候,我正在做任务,因为我只是一个初学者,我不知道发生了什么或如何解决它。 所有评论的部分都只是我尝试不同的方法来做到这一点。

import  sys
# YOUR CODE HERE
#small = input("Width, Height and Depth of small box: ")
#big = input("Width, Height and Depth of big box: ")

small_width = input("What is the width of the small box? ")
small_height = input("What is the height of the small box? ")
small_depth = input("What is the depth of the small box? ")

#small = 0
small = int(small_width)*int(small_height)*int(small_depth)

big_width = input("What is the width of the big box? ")
big_height = input("What is the height of the big box? ")
big_depth = input("What is the depth of the big box? ")

#big = 0
big = int(big_width)*int(big_height)*int(big_depth)

num = big%small
num = int(num)

print(num)

#if int(num) > 0
    #print("Number of " + small + " that will fit in " + big + " is: " + num)
#else:
    #print("Number of " + small + " that will fit in " + big + " is: 0")

它一直说这部分是错误的。

#if int(num) > 0
               ^

2 个答案:

答案 0 :(得分:2)

您在:语句末尾缺少冒号(if)。如果添加它,您将看到该行上的问题已修复,但在print条件的if语句中您将遇到另一个问题,因为您将打印文本结果以尝试连接int变量

答案 1 :(得分:1)

if语句后缺少冒号。 下载并安装PyCharm(有免费版) - IDE将突出显示此类错误。

import  sys
# YOUR CODE HERE
#small = input("Width, Height and Depth of small box: ")
#big = input("Width, Height and Depth of big box: ")

small_width = input("What is the width of the small box? ")
small_height = input("What is the height of the small box? ")
small_depth = input("What is the depth of the small box? ")

#small = 0
small = int(small_width)*int(small_height)*int(small_depth)

big_width = input("What is the width of the big box? ")
big_height = input("What is the height of the big box? ")
big_depth = input("What is the depth of the big box? ")

#big = 0
big = int(big_width)*int(big_height)*int(big_depth)

num = big%small
num = int(num)

print(num)

if int(num) > 0:
    print("Number of {} that will fit in {} is: {}".format(small, big, num))
    # print("Number of " + small + " that will fit in " + big + " is: " + num)
else:
    # print("Number of " + small + " that will fit in " + big + " is: 0")
    print("Number of {} that will fit in {} is: {}".format(small, big, 0))