This file contains hidden or 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 is a Rock-Paper-Scissors game. It prompts the user to select either Rock, Paper or Scissors. The computer then randomly selects either rock, paper or scissors and then compares the user's choice and the computer's choice. Finally it determines if the user has won and informs the user of the outcome""" | |
from random import randint | |
from time import sleep | |
options = ["R", "P", "S"] | |
LOSE = "You lost!" | |
WIN = "You Win!" | |
def decide_winner(user_choice, computer_choice): | |
print("%s") %(user_choice) | |
print("Computer Selecting...") | |
sleep(1) |
This file contains hidden or 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 prompts the user to select either a circle or a triangle and returns the area of that shape""" | |
from math import pi | |
from time import sleep | |
from datetime import * | |
now = datetime.now() | |
print "Welcome to Calculator 1.0" | |
print "%s/%s/%s %s:%s" %(now.month, now.day, now.year, now.hour, now.minute) | |
sleep(1) |
This file contains hidden or 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 randomly rolls a pair of dice and adds the values of the roll. | |
It then asks the user to guess a number, compares the user's guess to the total value and finally decides whether the winner is the user or the program and informs the user who the winner is""" | |
from random import randint | |
from time import sleep | |
def get_user_guess(): | |
user_guess = int(raw_input("Enter your guess:")) | |
return user_guess |
This file contains hidden or 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 creates a calendar that the user can interact with from the command line. It allows the user to: view the calendar, add an event to the calendar, update an existing event, delete an existing event""" | |
from time import sleep, strftime, localtime | |
USER_NAME = "Odanga" | |
calendar = {} | |
def welcome(): | |
print("Welcome to MyCalendar %s") %(USER_NAME) | |
print("MyCalendar is starting...") | |
sleep(1) | |
print("Today's date is: " + strftime("%A %B %d, %Y", localtime())) |
This file contains hidden or 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 creates a Python class tat can be used to create and manipulate a personal bank account. The Bank account class: accepts deposits, allows withdrawals, shows the balance and shows the details of the account.""" | |
class BankAccount(object): | |
balance = 0 | |
def __init__(self, name): | |
self.name = name | |
def __repr__(self): | |
return "This account belongs to %s and has a balance of $%.2f" %(self.name, self.balance ) | |
def show_balance(self): | |
print("%s's balance: $%.2f") %(self.name,\ |
This file contains hidden or 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
sample = ['GTA','GGG','CAC'] | |
def read_dna(dna_file): | |
dna_data = "" | |
with open(dna_file, "r") as f: | |
for line in f: | |
dna_data += line | |
return dna_data | |
def dna_codons(dna): |
This file contains hidden or 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 datetime | |
name = raw_input("Enter your name:") | |
age = int(input("Enter your age:")) | |
now = datetime.datetime.now() | |
year = now.year + (100 - age) | |
message = "Hey %s you will turn 100 years old in the year %d" %(name, year) | |
number = int(input("How many times would you like to print the message?")) | |
for i in range(number): | |
print message |
This file contains hidden or 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
number = int(input("Enter a number:")) | |
if number % 2 == 0 and number % 4 == 0: | |
print("%d is a multiple of both 2 and 4") % number | |
elif number % 2 == 0: | |
print("%d is an even number") % number | |
else: | |
print("%d is an odd number") % number | |
def num_check(): |
This file contains hidden or 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
# part 1 | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
for item in a: | |
if item < 5: | |
print(item), | |
# part 2 | |
b = [item for item in a if item < 5] | |
print("\n") | |
print(b) |
This file contains hidden or 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
list_ = [] | |
def divisor_check(): | |
num = int(input("Enter the number you wanna check:")) | |
divisor = 1 | |
for i in range(num): | |
if num % divisor == 0: | |
list_.append(divisor) | |
divisor += 1 | |
divisor_check() | |
print(list_) |
OlderNewer