python - 如何修复无效语法

标签 python

在标题为 #Title type and size 的部分中,我想打印出每个图 block 的定价,但我无法将数字相除。我该如何解决这个问题?谢谢

print("Welcome to Terry Cotta's Tiling Company!")

#Dimenstion of area to be tiled
areaLength = int(input('Input length of area to be tiled in metres: '))
if areaLength <= 0:
    print('Area cannot be lower than 0')
    areaLength = int(input('Input length of area to be tiled in metres: '))
areaWidth = int(input('Input width of area to be tiled: '))
if areaWidth <= 0:
    print('Area cannot be lower than 0')
    areaWidth = int(input('Input length of area to be tiled in metres: '))
areaArea = areaLength*areaWidth

#Tile type and size
tiles = {'ceramic': '3', 'granite': '5', 'marble': '10'}

for x in tiles:
    print(x.title() + " -  Small: $" + int(tiles[x])/2 + "  Medium: $" + tiles[x] + "  Large: $" + int(tiles[x])*(2)

tileType = input("What type of tile would you like? Ceramic, granite or marble?: ")
tileType = tileType.lower()
while tileSuitable != 'yes':
    if tileType not in tiles:
        print('We do not provide that type of tile. Please enter again.')
        tileType = input("What type of tile would you like? Ceramic, granite or marble?: ")
if tileType in tiles:
    tileSize = input('What size tile would you like? Small, medium or large: ') 

#        else:
#            print(tileType.title() + ' costs $' + tiles[tileType])
#            confirmTileType = input('Is this your desired material? ')
#            confirmTileType = confirmTileType.lower()
#            if confirmTileType == 'no':
#                tileType = input("What type of tile would you like? Ceramic, granite or marble. Type 'cost' for cost of materials: ")

最佳答案

这是因为你没有关闭打印功能

是:

print(x.title() + " -  Small: $" + int(tiles[x])/2 + "  Medium: $" + tiles[x] + "  Large: $" + int(tiles[x])*(2)

应该是:

print(x.title() + " -  Small: $" + int(tiles[x])/2 + "  Medium: $" + tiles[x] + "  Large: $" + int(tiles[x])*(2))

对代码进行小更改:

print("Welcome to Terry Cotta's Tiling Company!")
areaLength = int(input('Input length of area to be tiled in metres: '))


#You could loop until you get correct value


while areaLength <= 0:
    print('Area cannot be lower than 0')
    areaLength = int(input('Input length of area to be tiled in metres: '))
areaWidth = int(input('Input width of area to be tiled: '))

#Same here loop until you get the correct value 


while areaWidth <= 0:
    print('Area cannot be lower than 0')
    areaWidth = int(input('Input length of area to be tiled in metres: '))
areaArea = areaLength*areaWidth

tiles = {'ceramic': '3', 'granite': '5', 'marble': '10'}

for x in tiles:
    print(x.title() + " -  Small: $" + str(int(tiles[x])/2) + "  Medium: $" + tiles[x] + "  Large: $" + str(int(tiles[x])*(2)))

tileType = input("What type of tile would you like? Ceramic, granite or marble?: ")
tileType = tileType.lower()


#You had undeclared variable here so changed it


#And I really don't know what you were trying to do here 


while tileType != 'yes':
    if tileType not in tiles:
        print('We do not provide that type of tile. Please enter again.')
    tileType = input("What type of tile would you like? Ceramic, granite or marble?: ")
if tileType in tiles:
    tileSize = input('What size tile would you like? Small, medium or large: ')

关于python - 如何修复无效语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32498589/

相关文章:

python - 支持嵌套类型中自定义类的默认序列化

python - 如何解决网站上的 html5_webcam 问题?

python - ZeroRPC 自动分配空闲端口号

python - 在列表列表中添加换行符

python - ubuntu上python导入sidekit出错

python - Asyncpg 和 AWS Lambda

python - 如何一次有效地运行多个 Pytorch 进程/模型?回溯 : The paging file is too small for this operation to complete

python - 属性错误: 'module' object has no attribute 'ver'

python - 如何修补函数的 __code__?

python - Scrapy yield 项目作为 JSON 中的子项目