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
"""Convert cat years to human years.""" | |
# Build conversion dictionary: keys are cat years, values are human years. | |
conversion = {1: 15} | |
for age in (2, 3): | |
conversion[age] = conversion[age - 1] + 6 | |
for age in range(4, 21): | |
conversion[age] = conversion[age - 1] + 4 |
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
"""Show the number of lotto drawings to win.""" | |
import random | |
LOTTO_POOL = list(range(1, 50)) | |
lucky_numbers = random.sample(LOTTO_POOL, 6) | |
lucky_numbers.sort() | |
my_numbers = [] |
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
"""A game in which the player tries to guess a random number.""" | |
import random | |
def guess_number(): | |
"""Create variables and run the game loop.""" | |
number = random.randint(1, 100) | |
print("I'm thinking of a number between 1 and 100.") | |
print("Can you guess it?") |
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
"""Rock, Paper, Scissors. | |
There are two playing modes: user vs computer, and computer vs computer. | |
The game will continue until one player reaches a set score number. | |
Finally the user can decide whether to start a new game. | |
2018-03 | |
""" | |
import random |
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
"""A game of Hangman.""" | |
import string | |
import random | |
import sys | |
# Define constants. | |
FILENAME = "words.txt" | |
WRONG_MAX = 10 |
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
"""This program shows on what day the user will be able to retire.""" | |
from datetime import datetime | |
from dateutil.relativedelta import relativedelta | |
def get_dob(): | |
"""Get the user's date of birth.""" | |
print("Please enter your date of birth (dd.mm.yyyy):") | |
dob = "" |
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
class Cat(): | |
"""A prototype model for a cat.""" | |
def __init__(self, name, age, eye_color, weight_kg = 3): | |
"""Initialize attributes.""" | |
self.name = name | |
self.age = age | |
self.eye_color = eye_color | |
self.weight_kg = weight_kg | |
print(f"Welcome, {self.name}!") |
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
#!/usr/bin/env python3 | |
"""A game of Rock, Paper, Scissors against the computer.""" | |
import random | |
import time | |
FORMS = ("Rock", "Paper", "Scissors") | |
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
#!/usr/bin/env python3 | |
"""Encrypts a message using a Caesar cipher. | |
https://en.wikipedia.org/wiki/Caesar_cipher | |
""" | |
from string import ascii_uppercase | |
class Caesar(): |