How to make code work without import anything [closed]

98
December 09, 2019, at 5:00 PM
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 3 hours ago.

I wrote a code for my project but I did with imports , and now my professor told us that we can't import anything What I should change to make it work without import?

from __future__ import annotations
from typing import List, Dict

class Move:
    # constructor with parameters
    def __init__(self, cooperate=True):
        self.cooperate = cooperate
    # method to return string representation of object
    def __str__(self):
        return '.' if self.cooperate else 'x'
    # method to return formal string representation of object
    def __repr__(self) -> str:
        return f'Move({self.cooperate})'
    # method to return if given and current object are equal
    def __eq__(self, other: Move) -> bool:
        return self.cooperate == other.cooperate
    # method to change cooperation of current object
    def change(self) -> None:
        self.cooperate = not self.cooperate
    # method to create and return a new object
    # with the cooperation of current object
    def copy(self) -> Move:
        return Move(self.cooperate)

class PlayerException(Exception):
    def __init__(self, msg):
        self.msg = msg
    def __str__(self):
        return self.msg
    def __repr__(self):
        return f'PlayerException(\'{self.msg}\')'

class Player:
    PREVIOUS = 'previous'
    FRIEND = 'friend'
    CHEATER = 'cheater'
    GRUDGER = 'grudger'
    DETECTIVE = 'detective'
    STYLES = [PREVIOUS, FRIEND, CHEATER, GRUDGER, DETECTIVE]
    def __init__(self, style, points: int = 0, history: List[Move] = None):
        if history is None:
            history: List[Move] = list()
        self.history: List[Move] = history
        self.points = points
        # print(style, end=' | ')
        # print(history, end=' | ')
        print(style, end='\n')
        if self.STYLES.count(style) == 0:
            raise PlayerException(f'no style \'{style}\'.')
        self.style = style
    def __str__(self):
        return f"{self.style}({self.points})" + ''.join(
            str(move) for move in self.history)
    def __repr__(self):
        moves = ', '.join(f'Move({move.cooperate})' for move in self.history)
        return f"Player('{self.style}', {self.points}, [{moves}])"
    def reset_history(self):
        self.history: List[Move] = list()
    def reset(self):
        self.history: List[Move] = list()
        self.points: int = 0
    def update_points(self, amount: int):
        self.points = amount
    def ever_betrayed(self):
        return True in [not move.cooperate for move in self.history]
    def record_opponent_move(self, move: Move):
        self.history.append(move)
    def copy_with_style(self):
        return Player(self.style)
    def choose_move(self):
        if self.style == self.CHEATER:
            return Move(cooperate=False)
        return Move(cooperate=True)

# method to calculate and return turn payout for a round of moves
def turn_payouts(move_a, move_b):
    if move_a.__str__() == '.' and move_b.__str__() == '.':
        return 2, 2
    if move_a.__str__() == 'x' and move_b.__str__() == 'x':
        return 0, 0
    if move_a.__str__() == 'x' and move_b.__str__() == '.':
        return 3, -1
    if move_a.__str__() == '.' and move_b.__str__() == 'x':
        return -1, 3

def build_players(initials):
    k = {
        'p': Player.PREVIOUS,
        'c': Player.CHEATER,
        'd': Player.DETECTIVE,
        'f': Player.FRIEND,
        'g': Player.GRUDGER,
    }
    for i in initials:
        if i not in k.keys():
            raise PlayerException(f"no style with initial '{i}'.")
    return [Player(k[i]) for i in initials]

def composition(players: List[Player]):
    cnt: Dict[str, int] = dict()
    for i in players:
        if i.style not in cnt.keys():
            cnt[i.style] = 0
        cnt[i.style] += 1
    return cnt

def run_turn(player_a: Player, player_b: Player):
    if id(player_a) == id(player_b):
        raise PlayerException("players must be distinct.")
    player_a.update_points(player_a.points - 1)
    player_b.update_points(player_b.points - 1)
Rent Charter Buses Company
READ ALSO
Class as first argument for single dispatch

Class as first argument for single dispatch

As the documentation states the dispatch happens on the type of the first non-self or non-cls argumentIn this way, I'm trying to apply some function to a pandas DataFrame, which I would like it to be generic

122
Handling API Pagination, using a 'next.link" object

Handling API Pagination, using a 'next.link" object

I am using the odatanextLink found at the bottom of certain requests to handle pagination

98
Flask blog post extensive controls - How to control text formating, ability to add links, pictures etc

Flask blog post extensive controls - How to control text formating, ability to add links, pictures etc

I am building a website-blog using the Flask python web-frameworkI can create a blog post, wherein the content field is where all the text of my post goes

81
Using str_replace to replace a character and then 1 character after that

Using str_replace to replace a character and then 1 character after that

I have queried a Minecraft server and this is what it looks like "§f§6§lMINE§b§lHEROES §7[17-1

92