This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Tank: | |
def __init__(self, name): | |
self.name = name | |
self.ammo = 10 | |
self.health = 100 | |
def fire_at(self, target): | |
if self.ammo > 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Tank: | |
def __init__(self, name): | |
self.name = name | |
self.health = 100 | |
self.ammo = 5 | |
self.armor = 60 | |
def shoot(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the tank class | |
Tank <- function(health, armor, damage) { | |
list( | |
health = health, | |
armor = armor, | |
damage = damage | |
) | |
} | |
# Define the game function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
# Define player class | |
class Player: | |
def __init__(self): | |
self.health = 100 | |
self.thirst = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
# Define player class | |
class Player: | |
def __init__(self): | |
self.health = 100 | |
self.hunger = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
# Define player class | |
class Player: | |
def __init__(self): | |
self.health = 100 | |
self.hunger = 0 | |
self.thirst = 0 | |
self.shelter = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
# Define the options | |
options = ["rock", "paper", "scissors"] | |
# Initialize the score | |
player_score = 0 | |
computer_score = 0 | |
# Play the game |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
print("Welcome To Cowboy Game.\nYou are a cowboy.") | |
class Cowboy: | |
def __init__(self, name): | |
self.name = name | |
self.health = 100 | |
self.ammo = 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Team: | |
def __init__(self, name, offense, defense): | |
self.name = name | |
self.offense = offense | |
self.defense = defense | |
self.score = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hanoi(n, source, auxiliary, target): | |
if n > 0: | |
# Move n-1 discs from source to auxiliary | |
hanoi(n-1, source, target, auxiliary) | |
# Move the nth disc from source to target | |
print(f"Move disk {n} from {source} to {target}") | |
# Move the n-1 discs from auxiliary to target | |
hanoi(n-1, auxiliary, source, target) |