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
x = 10 | |
while x >= 0: | |
print(x) | |
x -= 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 | |
class Room: | |
rooms = [] | |
def __init__(self, name, description): | |
self.name = name | |
self.description = description | |
self.linked_rooms = {} | |
Room.rooms.append(self) # self.rooms.append |
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 | |
#Random choice is the optimum strategy according to game theory. However, behavioral economics show | |
#that players who win tend to stick with the same action while | |
#those who lose switch to the next action in a clockwise direction (where R → P → S is clockwise). | |
#MIT Technology Review April 30, 2014. | |
print ("This is a game called rock, paper, scissors.") | |
print (" ") | |
print ("The rules of the game are as follows: Paper covers Rock; Scissors cut Paper; Rock breaks 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
import random | |
rps_dict = {"rock": "scissors", "paper": "rock", "scissors": "paper"} | |
rps = input("please type rock, paper, or scissors \n") | |
computer_choice = random.choice(list(rps_dict.keys())) | |
if rps == computer_choice: | |
print("You both picked {} it is a tie!".format(rps)) |
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 | |
#character class, defines the player | |
class Character(): | |
def __init__(self, name = "none", hp = 100, ap = 65): | |
self.name = name | |
self.hp = hp #hit points | |
self.ap = ap #Attack points | |
#self.items = ["health potion", "sword"] #character items. Potentially... |
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 RockPaperScissors(): | |
import random | |
global options, cpu, user, x, y #There is no reason to make these global variables when they are inside a function | |
print("Welcome to rock, paper, scissors!\nType q if you want to quit the game.\nor!") | |
x = 0 | |
y = 0 | |
while True: | |
options = ["rock","paper","scissors"] | |
cpu = random.choice(options) | |
user = input("Pick one of the following: rock, paper or 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
# Play the fun game of Rock-Paper-Scissors: | |
import random | |
def rock_paper_scissors(): | |
options = ["rock", "paper", "scissors"] | |
auto_selection = random.choice(options) | |
user_selection = input ("\nSelect one of the following: \nROCK! PAPER! SCISSORS! ") | |
# You don't need ( ) around True |
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
# Hi Juan! Overall, your code looks good. However, there is a way to change your program | |
# using a data structure that will significantly shorten your program. Generally, when | |
# you have a bunch of if-statements, you should think about ways to shorten your code | |
# See if you can find a relationship between rock, papers, and scissors and use a | |
# data structure to take advantage of that relationship and shorten your code | |
import random | |
print ("Let's play 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
from urllib.request import Request, urlopen | |
from bs4 import BeautifulSoup | |
import requests | |
import csv | |
class Scraper: | |
def __init__(self): | |
self.links = [] | |
self.products = {} |
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 urllib.request | |
from bs4 import BeautifulSoup | |
class Scraper: | |
def __init__(self, site): | |
self.site = site | |
def scrape(self): | |
response = urllib.request.urlopen(self.site) |