我即将结束关于创建一个非常简单的战舰游戏的课程。基本上你有4次机会猜测船的位置。如果你输了:游戏结束了。如果你在所有4次机会之前获胜,那么你应该使用“ <html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<p>Click the table headers to change the sorting order:</p>
<div ng-app="myApp" ng-controller="namesCtrl">
<p>
<button type="button" ng-click="remove($index)">Delete Selected</button>
<button type="button" ng-click="">Edit Selected</button>
</p>
<table border="1" width="100%">
<tr>
<th>
<input type="checkbox" ng-model="selectAll" ng-click="checkAll()" ng-checked="allChecked()" />
</th>
<th></th>
<th>Sl no</th>
<th ng-click="orderByMe('name')">Name</th>
<th ng-click="orderByMe('country')">Country</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<tr ng-repeat="x in names | orderBy:myOrderBy">
<td>
<input type="checkbox" ng-model="x.select" ng-click="xsetting(x)" />
</td>
<td>{{x.select}}</td>
<td>{{$index+1}}</td>
<td>
<div ng-hide="editData[x.id]">{{x.name}}</div>
<div ng-show="editData[x.id]"><input type="text" ng-model="x.name" /></div>
</td>
<td>
<div ng-hide="editData[x.id]">{{x.country}}</div>
<div ng-show="editData[x.id]"><input type="text" ng-model="x.country" /></div>
</td>
<td>
<button type="button" ng-click="Delete(x)">Delete</button>
</td>
<td>
<button ng-hide="editData[x.id]" ng-click="edit(x)">Edit</button>
<button ng-show="editData[x.id]" ng-click="update(x)">Update</button>
<button ng-show="editData[x.id]" ng-click="cancel(x)">Cancel</button>
</td>
</tr>
</table>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', ['$scope', 'filterFilter', function($scope, filterFilter) {
$scope.names = [{
name: 'Jani',
country: 'Norway',
id: '0'
}, {
name: 'Carl',
country: 'Sweden',
id: '1'
}, {
name: 'Margareth',
country: 'England',
id: '2'
}, {
name: 'Hege',
country: 'Norway',
id: '3'
}, {
name: 'Joe',
country: 'Denmark',
id: '4'
}, {
name: 'Gustav',
country: 'Sweden',
id: '5'
}, {
name: 'Birgit',
country: 'Denmark',
id: '6'
}, {
name: 'Mary',
country: 'England',
id: '7'
}, {
name: 'Kai',
country: 'Norway',
id: '8'
}];
//for sorting the rows
$scope.orderByMe = function(x) {
$scope.myOrderBy = x;
}
//single row deletion
$scope.Delete = function(x) {
$scope.names.splice($scope.names.indexOf(x), 1);
};
//selecting all checkboxes in the table
$scope.checkAll = function() {
angular.forEach($scope.names, function(x) {
x.select = $scope.selectAll;
});
};
//select all checkbox automatically checked if all individual rows checked
$scope.allChecked = function() {
return $scope.names.filter(obj => obj.select).length === $scope.names.length
}
//for selecting and deleting checked items
$scope.remove = function() {
$scope.names = filterFilter($scope.names, function(x) {
return !x.select;
});
};
//edit the rows using edit button
$scope.editData = {};
for (var i = 0, length = $scope.names.length; i < length; i++) {
$scope.editData[$scope.names[i].id] = false;
};
$scope.edit = function(x) {
$scope.editData[x.id] = true;
};
$scope.update = function(x) {
$scope.editData[x.id] = false;
};
$scope.cancel = function(x) {
};
}]);
</script>
</body>
</html>
”功能结束游戏。
问题是:插入“break
”后,我收到错误消息:
break
这是我的代码,请感谢您的任何帮助,非常感谢:
File "python", line 33
SyntaxError: 'break' outside loop
答案 0 :(得分:0)
你的休息确实超出了循环。尝试在第31行的if-else语句中修改缩进,如下所示:
for turn in range(4):
...
if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sunk my battleship!"
break
else:
...