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 Bike: | |
def __init__(self, name, speed): | |
self.name = name | |
self.speed = speed | |
self.distance = 0 | |
def move(self): | |
self.distance += self.speed * random.randint(1, 5) |
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
bike1 <- list(name = "Bike 1", speed = 20, distance = 0) | |
bike2 <- list(name = "Bike 2", speed = 25, distance = 0) | |
bike3 <- list(name = "Bike 3", speed = 18, distance = 0) | |
move_bike <- function(bike) { | |
bike$distance <- bike$distance + bike$speed * sample(1:5, 1) | |
} | |
print_position <- function(bike) { | |
cat(paste(bike$name, "is at position", bike$distance, ".\n")) |
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 Car: | |
def __init__(self, name, speed): | |
self.name = name | |
self.speed = speed | |
self.distance = 0 | |
def move(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
import random | |
# Monster class | |
class Monster: | |
def __init__(self, name, health, attack): | |
self.name = name | |
self.health = health | |
self.attack = attack |
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
from random import randint | |
board = [] | |
# Create the board | |
for x in range(5): | |
board.append(["O"] * 5) | |
# Function to print the board |
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 | |
# Virtual Pet Class | |
class VirtualPet: | |
def __init__(self, name): | |
self.name = name | |
self.hunger = 50 |
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
# Python Program to illustrate | |
# Hangman Game | |
import random | |
from collections import Counter | |
print(" Hangman") | |
print("======================================\n") | |
someWords = '''apple banana mango strawberry orange grape pineapple apricot lemon coconut watermelon cherry papaya berry peach lychee muskmelon''' | |
someWords = someWords.split(' ') | |
# randomly choose a secret word from our "someWords" LIST. |
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 os | |
import time | |
# Define the game constants | |
BOARD_WIDTH = 20 | |
BOARD_HEIGHT = 10 | |
SNAKE_INITIAL_LENGTH = 3 | |
SNAKE_INITIAL_X = BOARD_WIDTH // 2 | |
SNAKE_INITIAL_Y = BOARD_HEIGHT // 2 |
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 game board | |
board_size = 5 | |
num_mines = 5 | |
board = [[0 for x in range(board_size)] for y in range(board_size)] | |
# Place the mines | |
for i in range(num_mines): | |
x = random.randint(0, board_size - 1) |
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 questions | |
questions = { | |
"What is the capital of France?": "Paris", | |
"What is the largest planet in our solar system?": "Jupiter", | |
"Who wrote the Harry Potter book series?": "J.K. Rowling", | |
"What is the largest country in the world?": "Russia", | |
"What is the highest mountain in the world?": "Mount Everest" | |
} |