2015-09-10 110 views
1

在標題爲#標題類型和大小的部分,我想打印出每個瓷磚的定價,但我不能劃分數字。我將如何解決這個問題?由於如何解決無效的語法

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: ") 
+0

複製並粘貼您的錯誤在這裏。 – wolendranh

+0

它只是說'無效語法' – Lazlt

+0

只是試圖評論一些代碼,您可能會發現錯誤的正確位置。簡單地將所有代碼粘貼到這裏並要求其他人檢查 – linpingta

回答

2

那是因爲你沒有關閉print function

是:

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: ') 
+0

好極了,但現在如何才能打印所有價格呢?我試過轉換爲整數和類似的東西,但它沒有工作 – Lazlt

+0

@dbab看到編輯改變了你的理解 – The6thSense

+0

@VigneshKalai非常感謝您的幫助! – Lazlt