Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file added Rib/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions Rib/ave2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Average List
# Create a program that prints the average of the values in the list: a = [1, 2, 5, 10, 255, 3]

print 'For the following list: '
a = [1, 2, 5, 10, 255, 3]
print a
print 'The average of the values in the list is: ' ,sum(a)/2

10 changes: 10 additions & 0 deletions Rib/checker2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Assignment: Checkerboard
# Write a program that prints a 'checkerboard' pattern
# to the console.

def checkerboard():

for i in range(4):
print"* * * * "
print" * * * *"
checkerboard()
21 changes: 21 additions & 0 deletions Rib/coins2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Write a function that simulates tossing a coin 5,000 times. Your function should print how many times the
# head/tail appears.

import random

def coin_toss():
t_count = 0
h_count = 0
print "Starting the program..."
for i in range(5000):
random_num = random.randint(0, 1)
if random_num == 0:
t_count += 1
result = "tail"
else:
h_count += 1
result = "head"
print "Attempt #" + str(i + 1) + ": Flipping a coin... It's a " + result + "! ... Got " + str(t_count) + " tail(s) so far and " + str(h_count) + " head(s) so far"
print "Ending the program, thank you!"

coin_toss()
21 changes: 21 additions & 0 deletions Rib/compare2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Write a program that compares two lists and prints a message depending on if the inputs are identical or not.

# Your program should be able to accept and compare two lists: list_one and list_two. If both lists are identical
# print "The lists are the same". If they are not identical print "The lists are not the same." Try the following test
# cases for lists one and two:



def compare(list1,list2):
if len(list1) != len(list2):
print 'The lists are not the same.'
return False
for i in range(len(list1)):
if list1[i] != list2[i]:
print 'The lists are not the same'
return False
print 'The lists are the same'

list1 = [1,4,6,7,5,34]
list2 = [2,4,5,7,7,75]
compare(list1,list2)
20 changes: 20 additions & 0 deletions Rib/dict_in2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Assignment: Dictionary in, tuples out
# Write a function that takes in a dictionary and returns a list of tuples where the first tuple item is the key
# and the second is the value. Here's an example:

a_dict = {
"Speros": "(555) 555-5555",
"Michael": "(999) 999-9999",
"Jay": "(777) 777-7777"
}


def my_dict(a_dict):

print "{}".format(dict.items(a_dict))

my_dict(a_dict)




41 changes: 41 additions & 0 deletions Rib/filter_type2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Assignment: Filter by Type
# Write a program that, given some value, tests that value for its type. Here's what you should do for each type:

# Integer
# If the integer is greater than or equal to 100, print "That's a big number!" If the integer is less than 100,
# print "That's a small number"


# question = 'Please enter an integer from 1 to 100 '
# print ('Please an integer from 1 to 100,')


# a = int(raw_input(question))

# if a <= 100=True

# if True :
# print 'Thats a small number!'
# elif:
# print 'Thats a big number!'
# else:
# print ("That wasnt a number between 1 and 100. Please try again."

def whatisit(test):
if type(test) is int:
if (test) <= 100:
print "Small Number"
else:
print "Big Number!"
elif type(test) is str:
if len(test) <= 100:
print "Short Sentence"
else:
print "Long Sentence"
elif type(test) is list:
if len(test) <=10:
print "Short List"
else:
print "Big List!"

whatisit([1,2,43,556,4,5,6,3,2,3,67,8,"sdflk"])
Empty file added Rib/find2.py
Empty file.
19 changes: 19 additions & 0 deletions Rib/find_chr2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Assignment: Find Characters
# Write a program that takes a list of strings and a string containing a single character,
# and prints a new list
# of all the strings containing that character.

def command_F(string_list,char_kb):
new_list = []
for i in string_list:
if char_kb in i:
new_list.append(i)
print 'This is the new list: '
print new_list

words = ['hello','world','my_name', 'is', 'Anna']
char = 'o'

command_F(words,char)


16 changes: 16 additions & 0 deletions Rib/first2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# First and Last
# Print the first and last values in a list like this one: x = ["hello",2,54,-2,7,12,98,"world"].
# Now create a new list containing only the first and last values in the original list. Your code should work for any list.

x = ["hello",2,54,-2,7,12,98,"world"]
i=0
print x[0]

print 'The first value for the array is : ', x[0]
print 'The last value for the array is : ', x[len(x)-1]

#Creating a new list containing only the first and last values in the original list. Your code should work for any list.
print 'New List is: ', [x[0], x[-1]]



11 changes: 11 additions & 0 deletions Rib/funwfunc2_odd_even.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Create a function called odd_even that counts from 1 to 2000.
# As your loop executes have your program print the number of that
# iteration and specify whether it's an odd or even number.

def odd_even(size):
for x in range(1, size):
if x %2 != 0:
print "The number is {}. This is an odd number.".format(x)
else:
print "The number is {}. This is an even number.".format(x)
odd_even(2000)
14 changes: 14 additions & 0 deletions Rib/hello_flask2/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from flask import Flask, render_template # Import Flask to allow us to create our app.
app = Flask(__name__)
# Global variable __name__ tells Flask whether or not we are running the file
# directly, or importing it as a module.
@app.route('/')
@app.route('/success')
def success():
return render_template('success.html') # The "@" symbol designates a "decorator" which attaches the following
# function to the '/' route. This means that whenever we send a request to
# localhost:5000/ we will run the following "hello_world" function.
def hello_world():
return render_template('index.html')
# Return the string 'Hello World!' as a response.
app.run(debug=True) # Run the app in debug mode.
12 changes: 12 additions & 0 deletions Rib/hello_flask2/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Index Page</title>
</head>
<body>
<h1>Hello Flask!</h1>
<h3>My name is Anna</h3>

</body>
</html>
10 changes: 10 additions & 0 deletions Rib/hello_flask2/templates/success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Success Page</title>
</head>
<body>
<h2>You have successfully created another GET route that serves a page!</h2>
</body>
</html>
7 changes: 7 additions & 0 deletions Rib/min2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Min and Max
# Print the min and max values in a list like this one: x = [2,54,-2,7,12,98]. Your code should work for any list.
x = [2,54,-2,7,12,98]

print 'Minimum value for the array is : ', min(x)
print 'Maximum value for the array is : ', max(x)

8 changes: 8 additions & 0 deletions Rib/mult_sum_ave2/ave2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Average List
# Create a program that prints the average of the values in the list: a = [1, 2, 5, 10, 255, 3]

print 'For the following list: '
a = [1, 2, 5, 10, 255, 3]
print a
print 'The average of the values in the list is: ' ,sum(a)/2

18 changes: 18 additions & 0 deletions Rib/mult_sum_ave2/multi_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Multiples
# Part I - Write code that prints all the odd numbers from 1 to 1000. Use the for loop and don't use a list to do
# this exercise.

for x in range(1, 1001):
if (x % 3 == 0):
print x

# Multiples
# Part II - Create another program that prints all the multiples of 5 from 5 to 1,000,000.:
sum = 1

for i in range(5, 1000000):
if i % 5 % 1000000 == 0:
sum += i

print("The sum of multiples of 5 between 5 to 1000000 is: " , + sum)

9 changes: 9 additions & 0 deletions Rib/mult_sum_ave2/sums2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Sum List
# Create a program that prints the sum of all the values in the list: a = [1, 2, 5, 10, 255, 3]

print 'For the following list: '
a = [1, 2, 5, 10, 255, 3]
print a
print 'The sum of the list is: ', sum(a)


22 changes: 22 additions & 0 deletions Rib/multiply2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Multiply:
# Create a function called 'multiply' that iterates through each value in a list (e.g. a = [2, 4, 10, 16])
# and returns a list where each value has been multiplied by 5. The function should multiply each value in the
# list by the second argument. For example, let's say:

# a = [2,4,10,16]

# Then:

# b = multiply(a, 5)
# print b

# Should print [10, 20, 50, 80 ].

def multiply(list):
new_list = []
for i in list:
new_list += [i*5]
if i >= len(list):
print new_list

multiply([1,2,3,4])
Loading