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
#include <cs50.h> | |
#include <stdio.h> | |
#include <string.h> | |
// Max voters and candidates | |
#define MAX_VOTERS 100 | |
#define MAX_CANDIDATES 9 | |
// preferences[i][j] is jth preference for voter i | |
int preferences[MAX_VOTERS][MAX_CANDIDATES]; |
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
letter = "a" | |
# converts a letter to ascii code | |
ascii_code = ord(letter) | |
# converts ascii code to a letter | |
letter_res = chr(ascii_code) | |
encoded_phrase = "" | |
phrase = raw_input("Type the phrase you'd like to see encoded. ") |
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 zeller(A,B,C,D): | |
if A == 1 or A == 2: | |
A+=10 | |
C-=1 | |
else: | |
A-=2 | |
W = (13*A-1) / 5 | |
X = C / 4 | |
Y = D / 4 | |
Z = W + X + Y + B + C - 2*D |
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 roots(a,b,c): | |
d = b**2-4*a*c | |
#print d | |
if d < 0: | |
return "Too complex.", "d =" + str(d) | |
elif d == 0: | |
r1=-b/2*a | |
return r1, "d =" + str(d) | |
else: |
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
### The following are my attempts at homework 2.3 for MIT 6.189 | |
###http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/assignments/MIT6_189IAP11_hw2.pdf | |
### Everything here works, and evaluates correctly, but I'd love some feedback. | |
### Particularly with understanding the intention behind the multadd method. | |
### In a few of my examples I use it essentially just to generate a sum (multiplying said sum by one). | |
### Is there a saavier way to use this, more in keeping with the spirit of the exercise? | |
## 1 - multadd function | |
##### YOUR CODE HERE ##### |