在标题为 #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/