Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Last active October 24, 2022 04:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Quingsley/5401de1c6b4849e94f0ed12bf38dab3c to your computer and use it in GitHub Desktop.
Save Quingsley/5401de1c6b4849e94f0ed12bf38dab3c to your computer and use it in GitHub Desktop.
players-game
//A group of twenty boys are in a football pitch and they want to play football.
//I want you to help me create a programme using python or any other programming
//language that will help me to break the group into two football teams each consisting of 10 players.
//The programme should first ask me to input the names of the two teams; the first team name then the second team name.
//Then after that, it should ask me to input the list of names of the twenty boys.
//After inputing these names, the programme should give me an output of the two final teams with the team name on top of a list of the 10 players
//of each team. The team players should be selected in the order of odd number and even number respectively according to the list of names that will be provided.
void main() {
// A list of players n/b dartpad does not allow inputs in browser ):
List players = ['Doctor',
'Bub',
'Colonel',
'Biffle',
'ColdBrew',
'Snickerdoodle',
'Genius',
'Turkey',
'Cruella',
'Cheeto',
'IceQueen',
'Shrinkwrap',
'Pig',
'Marshmallow',
'Chewbacca',
'HotSauce',
'Pearl',
'Pansy',
'Cutie',
'Cloud'];
List<TeamA> teamA = []; // the first team
List<TeamB> teamB = []; // the second team
for(int index = 0; index < players.length; index ++) {
// teams divided in even/odd numbers
if((index + 1) % 2 == 0) { // check if current index is even and add to teamA
teamA.add(
TeamA(firstName: players[index], number: (index + 1))
);
} else { // if not even add to teamB
teamB.add(
TeamB(firstName: players[index], number: (index + 1))
);
}
}
print('teamA');
for(var player in teamA) {
print('${player.number} : ${player.firstName}');
}
print('teamB');
for(var player in teamB) {
print('${player.number} : ${player.firstName}');
}
}
//Defining models of team A and Team B
class TeamA {
String firstName;
int number;
TeamA({required this.firstName, required this.number});
}
class TeamB {
String firstName;
int number;
TeamB({required this.firstName, required this.number});
}
@enzeyi
Copy link

enzeyi commented Oct 24, 2022

Nice Program!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment