本文整理汇总了Python中Helper.check_incorrect_input方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.check_incorrect_input方法的具体用法?Python Helper.check_incorrect_input怎么用?Python Helper.check_incorrect_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper
的用法示例。
在下文中一共展示了Helper.check_incorrect_input方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: summary
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import check_incorrect_input [as 别名]
def summary(state):
"""
Provides a summary of selected player
:param state: current state of variables
:return: prints a summary of the player
"""
# Initialize variables
stat_rankings = defaultdict(lambda: (defaultdict(float)))
for player in state.normalized_player_statistics[state.iteration]:
for statistic_name in state.normalized_player_statistics[state.iteration][player]:
stat_rankings[statistic_name][player] = \
state.normalized_player_statistics[state.iteration][player][statistic_name]
# Decide which player to view the stats of
while state.player_to_obtain is None:
desired_player = raw_input("Enter a player name: ").lower()
# If the input is valid, remove player from draft and add them to a team
if desired_player in state.cumulative_player_statistics[state.iteration]:
state.update_player_to_obtain(desired_player)
# Suggests player names if input is incorrect
else:
Helper.check_incorrect_input(desired_player, state.normalized_player_statistics[state.iteration].keys())
return Helper.calculate_player_summary(stat_rankings, state.player_to_obtain)
示例2: swap
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import check_incorrect_input [as 别名]
def swap(state):
"""
Shows the change in statistics if a player is swapped from your team
:param state: current state of variables
:return: prints statistic changes
"""
# Initialize variables
for user in state.teams:
state.teams[user] = Helper.lowercase(state.teams[user])
state.teams_storage = copy.deepcopy(state.teams)
if state.player_to_obtain is None and state.player_to_trade is None:
state.update_player_to_trade(raw_input("Enter the player you want to remove from your team: ").lower())
state.update_player_to_obtain(raw_input("Enter the player you want to add to your team: ").lower())
print ""
# If the input is valid, analyze statistic changes
if state.player_to_trade in state.cumulative_player_statistics[state.iteration] \
and state.player_to_trade in state.teams[state.current_user] \
and state.player_to_obtain in state.cumulative_player_statistics[state.iteration] \
and state.player_to_obtain not in state.teams[state.current_user]:
state.teams = copy.deepcopy(state.teams_storage)
return Helper.evaluate_player_swap(state.teams, state.player_to_trade, state.player_to_obtain,
state.normalized_player_statistics[state.iteration], state)
# Notifies user if player is not in their team
elif state.player_to_trade not in state.teams[state.current_user]:
print state.player_to_trade.title(), "is not on your team"
elif state.player_to_obtain in state.teams["Chris S"]:
print state.player_to_obtain.title(), "is already on your team"
# Suggests player names if input is incorrect
elif state.player_to_trade not in state.cumulative_player_statistics[state.iteration]:
Helper.check_incorrect_input(state.player_to_trade, state.normalized_player_statistics[state.iteration].keys())
else:
Helper.check_incorrect_input(state.player_to_obtain, state.normalized_player_statistics[state.iteration].keys())
示例3: trade
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import check_incorrect_input [as 别名]
def trade(state):
"""
Suggests players on your team to trade for a given player
:param state: current state of variables
:return: prints players to trade and their rankings
"""
# Initialize variables
players_on_team = Helper.lowercase(state.teams[state.current_user])
for x in state.teams:
state.teams[x] = Helper.lowercase(state.teams[x])
while state.player_to_obtain is None:
desired_player = raw_input("Enter the player you are trying to move: ").lower()
if desired_player in state.cumulative_player_statistics[state.iteration]:
state.update_player_to_obtain(desired_player)
else:
Helper.check_incorrect_input(desired_player, state.normalized_player_statistics[state.iteration].keys())
return Helper.find_trade_possibilities(state.cumulative_player_statistics[state.iteration],
state.normalized_player_statistics[state.iteration],
state.player_to_obtain, players_on_team, state)
示例4: draft
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import check_incorrect_input [as 别名]
#.........这里部分代码省略.........
# Store player names for input error checking
all_players = [str(row[0]).lower() for row in cursor.execute("""SELECT name FROM Contributions;""")]
# Determine where players are projected to be picked
projected = defaultdict(int)
with open('files/draft/projected_picks.txt') as f2:
for i, line in enumerate(f2.readlines()):
name = line.lower().rstrip()
projected[name] = i + 1
for pick in range(1, (participants * rounds_num) + 1):
# Breaks upon user request
if end:
break
# Re-initialize success variable
success = False
print '\nPick {} in progress...'.format(pick)
while not success:
# Print draft recommendations on user's pick
if pick in pick_numbers or pick == 1:
print ''
for draft_pick in Helper.optimize_draft(pick_numbers, projected, contribution, top_players, my_team,
taken + removed + my_team.keys(), pick):
if draft_pick[1] == '0':
print '{}. {} - DRAFTED'.format(str(my_team[draft_pick[0]]), draft_pick[0].title())
else:
print '{}. {}'.format(draft_pick[1], draft_pick[0].title())
# \ before a name indicates a new player
player = raw_input("\nEnter a player name: ").lower()
# Allows user to end function
if player == "end":
end = True
success = True
# Removes players from optimal draft calculation
elif player == 'remove':
removed.append(raw_input('Who would you like to remove?: '))
print ''
# Allows user to swap picks
elif player == 'swap':
old_pick = int(raw_input('Which pick are you losing?: '))
new_pick = int(raw_input('Which pick are you getting?: '))
print ''
if old_pick in pick_numbers:
pick_numbers.pop(pick_numbers.index(old_pick))
pick_numbers.append(new_pick)
# Calculates optimal draft upon request
elif player == 'draft' and pick not in pick_numbers and pick != 1:
print ''
for draft_pick in Helper.optimize_draft(pick_numbers, projected, contribution, top_players, my_team,
taken + removed + my_team.keys(), pick):
if draft_pick[1] == '0':
print '{}. {} - DRAFTED'.format(str(my_team[draft_pick[0]]), draft_pick[0].title())
else:
print '{}. {}'.format(draft_pick[1], draft_pick[0].title())
else:
# If the input is valid, remove player from draft and add them to a team
if (player in all_players or player[0] == '\\') and player not in taken:
player = player.replace('\\', '')
success = True
if pick in pick_numbers:
# Update which players are on user's team
my_team[player] = pick
# Add the player to the team database
cursor.execute("""INSERT INTO Teams VALUES ("{}", "{}")""".format(player, ME))
else:
user = raw_input(("Who drafted " + player.title() + "?: ")).lower()
taken.append(player)
# If the user is new, add them to the database
if user not in all_users:
all_users.append(user)
cursor.execute("""INSERT INTO Participants VALUES ("{}");""".format(user))
# Add the player to the team database
cursor.execute("""INSERT INTO Teams VALUES ("{}", "{}")""".format(player, user))
elif player in taken:
print '{} has already been drafted'.format(player.title())
# Suggests player names if input is incorrect
else:
Helper.check_incorrect_input(player, set(all_players) - set(taken))
# Close database connection
cursor.close()
connection.close()