没有quoations的Python打印

时间:2017-10-23 14:10:51

标签: python

我的代码低于输出" F",如何在没有"(引号)的情况下打印字符串?需要什么代码?请参阅我的完整代码答案

elif guess_row == ship_row and guess_col == ship_col: #F stands for found
                print("Congradulations you captured a ship")
                guess_amount = guess_amount - 1
                grid[guess_row][guess_col] = str('F')
                score = score + 10

1 个答案:

答案 0 :(得分:0)

这是我的大部分代码 并使用仍在引号中的字母打印网格

#ln36 code for plotting on grid -guess if statement
    score = 0 #keeps the score of the game 10- to hit a ship and -5 for empty space
    while guess_amount > 0:
        guess_row = int(input("How many rows across? "))#code for the person guessing
        guess_col = int(input("How many colums across? "))#code for the person guessing

        if guess_row not in range(col) or guess_col not in range(row):
            print("sorry that is out of range try again")

        elif guess_row == ship_row and guess_col == ship_col: #F stands for found
            print("Congradulations you captured a ship")
            guess_amount = guess_amount - 1
            grid[guess_row][guess_col] = 'F'
            score = score + 10

        elif guess_row != ship_row or guess_col != ship_col: #X stands for empty space
             print("Ooops there was no ship there")
             guess_amount = guess_amount - 1
             grid[guess_row][guess_col] = 'X'
             score = score - 5 

    #ln58 code for printing results       
    if grid[ship_row][ship_col] != 'F':
        grid[ship_row][ship_col] = 'S' #S for ship

    if grid[ship_row2][ship_col2] != 'F':
        grid[ship_row2][ship_col2] = 'S'
    for l in grid:
        print(l)

    print("total score", score)