Extra Credit HELP!


#1

Hello, city_2 says invalid syntax and I can't figure out what.

name = input('Player One, what is your name? ')
name_2 = input('Player Two, what is your name? ')
from random import randint
board = []
for x in range(15):
board.append(["O"] * 15)
def print_board(board):
for row in board:
print(" ".join(row))
print('This is the turn of %s' % (name))
print_board(board)
x = int(input('Where do you want your first city (row)? '))
a = int(input('Where do you want your first city (collum)? '))
board[x][a] = 'C'
print_board(board)
q = int(input('Where do you want your troops (row)? '))
w = int(input('Where do you want your troops (collum)? '))
board[q][w] = 'T'
print('This is the turn of %s' % (name_2))
print_board(board)
x_2 = int(input('Where do you want your first city (row)? '))
a_2 = int(input('Where do you want your first city (collum)? '))
board[x_2][a_2] = 'C'
print_board(board)
q_2 = int(input('Where do you want your troops (row)? '))
w_2 = int(input('Where do you want your troops (collum)? '))
board[q_2][w_2] = 'T'
print_board(board)
money = 0
profit = 20
expenses = 15
for turn in range(15):
print('This is the turn of %s.' % (name))
money = money + profit - expenses
print('You have %s dollars.' % (money))
buying = input('Would you like to upgrade or buy anything? You can buy new troops and cities! (yes or no) ')
if buying == 'yes':
item = input('What would you like to buy? (cities or troops) ')
cities = 5
troops = 5
if item == 'cities':
city = int(input('Where would you like to put the city? (row) ')
city_2 = int(input('Where would you like to put the city? (col) ')
board[city][city_2] = 'C'
expenses = expenses + cities
new_money = profit + money - expenses
print('You now have %s dollars.' % (new_money))
print_board(board)
elif item == 'troops':
expenses = expenses + troops
new_money = profit + money - expenses
troops = int(input('Where would you like to move your city? (row) ')
troops_2 = int(input('Where would you like to move your city? (col) ')
board[troops][troops_2] = 'C'
print('You now have %s dollars.' % (new_money))
print_board(board)
first = input('%s, do you want to move your troops (yes or no)? ' % (name))
if first == 'yes':
o = int(input('Where would you like to move them? (Row, remember, you can only move one space!) '))
r = int(input('Where would you like to move them? (Collum, remember, you can only move one space!) '))
board[q][w] = 'O'
board[o][r] = 'T'
if(board[o][r] == 'T'):
attack = input('You cannot move troops here without attacking. Would you like to attack? (yes or no) ')
if attack == 'yes':
print('You are attacking %s!' % (name_2))
else:
no_attack = int(input('You are not attacking. Would you like to move them anywhere else? (row) '))
no_attack_col = int(input('You are not attacking. Would you like to move them anywhere else? (col) '))
board[o][r] = 'O'
board[no_attack][no_attack_col] = 'T'
print_board(board)
else:
board[o][r] = 'T'
board[q][w] = 'O'
print_board(board)
else:
print_board(board)
print('Your turn is over, %s.' % (name))
print("It is now %s's turn." % (name_2))


#2

First format your code properly then someone can try to help you.you also know indentation is very important for python.

Do the following:

  • copy your code and paste it here
  • select the whole code
  • click on the </> above

#3

idk :sunglasses: :sunny:
:wink:
:taco:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.