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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ __pycache__/

# Distribution / packaging
.Python
.idea
test*.py
*.zip
.mypy_cache
env/
build/
develop-eggs/
Expand Down
18 changes: 18 additions & 0 deletions students/navidbahadoran/Lesson01/Monkey_Trouble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
title: Monkey_Trouble
change log:
NBahadoran, 1/13/2018, Created Monkey_Trouble.py
"""

def monkey_trouble(a_smile, b_smile):
"""
We have two monkeys, a and b, and the parameters a_smile and b_smile indicate
if each is smiling. We are in trouble if they are both smiling or if neither
of them is smiling. Return True if we are in trouble.
monkey_trouble(True, True) → True
monkey_trouble(False, False) → True
monkey_trouble(True, False) → False
"""
return(a_smile == b_smile )

print(monkey_trouble(False,False))
19 changes: 19 additions & 0 deletions students/navidbahadoran/Lesson01/Sleep_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
title: Sleep_in
change log:
NBahadoran, 1/13/2018, Created Sleep_in.py
"""

def sleep_in(weekday, vacation):
"""
The parameter weekday is True if it is a weekday, and the parameter vacation is True
if we are on vacation. We sleep in if it is not a weekday or we're on vacation.
Return True if we sleep in.
sleep_in(False, False) → True
sleep_in(True, False) → False
sleep_in(False, True) → True
"""
return(vacation or(not weekday))


print(sleep_in(False,False))
13 changes: 13 additions & 0 deletions students/navidbahadoran/Lesson01/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
def name_error():
raise NameError
def type_error():
raise TypeError
def syntax_error():
raise SyntaxError
def attribute_error():
raise AttributeError
name_error()
type_error()
syntax_error()
attribute_error()
17 changes: 17 additions & 0 deletions students/navidbahadoran/Lesson01/def_21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
title: def_21
change log:
NBahadoran, 1/13/2018, Created def_21.py
"""
def diff21(n):
"""
Given an int n, return the absolute difference between n and 21,
except return double the absolute difference if n is over 21.
diff21(19) → 2
diff21(10) → 11
diff21(21) → 0
"""
return(abs(n-21) if n<21 else 2*abs(n-21))


print(diff21(23))
19 changes: 19 additions & 0 deletions students/navidbahadoran/Lesson01/sum_double.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
title: Sum_double
change log:
NBahadoran, 1/13/2018, Created sum_double.py
"""

def sum_double(a, b):
"""
Given two int values, return their sum.
Unless the two values are the same, then return double their sum.
sum_double(1, 2) → 3
sum_double(3, 2) → 5
sum_double(2, 2) → 8
"""
return(a+b if a!=b else (a+b)*2)

print(sum_double(1,1))
print(sum_double(1,2))
#
1 change: 1 addition & 0 deletions students/navidbahadoran/Lesson01/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the folder I will use for assignment 01
32 changes: 32 additions & 0 deletions students/navidbahadoran/Lesson02/Fizz_Buzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
title: Fizz_Buzz
Desc: for the number in the range of 1 to n:
print “Fizz” instead of the number for multiples of three
print “Buzz” instead of the number for the multiples of five .
For numbers which are multiples of both three and five print “FizzBuzz” instead.
change log:
NBahadoran, 1/20/2018, Created Fizz_Buzz.py
"""

def fizz_buzz(n):
"""
for the number in the range of 1 to n:
print “Fizz” instead of the number for multiples of three
print “Buzz” instead of the number for the multiples of five .
For numbers which are multiples of both three and five print “FizzBuzz” instead.
else print number.
:param n: the input from user that need to be printed
:return:
"""
for num in range(1,n+1):

if (num % 3 == 0) and (num % 5 == 0):
print("FizzBuzz")
elif num % 3 == 0:
print("Fizz")
elif num % 5 == 0:
print("Buzz")
else:
print(num)


19 changes: 19 additions & 0 deletions students/navidbahadoran/Lesson02/front3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
title: front3
change log:
NBahadoran, 1/19/2018,Created front3.py
"""


def front3(str):
"""
Given a string, we'll say that the front is the first 3 chars of the string.
If the string length is less than 3, the front is whatever is there. Return
a new string which is 3 copies of the front.
front3('Java') → 'JavJavJav'
front3('Chocolate') → 'ChoChoCho'
front3('abc') → 'abcabcabc'
"""
if len(str)<3:
return str*3
return str[0:3]*3
15 changes: 15 additions & 0 deletions students/navidbahadoran/Lesson02/front_back.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
title: front_back
change log:
NBahadoran, 1/19/2018,Created front_back.py
"""
def front_back(str):
"""
Given a string, return a new string where the first and last chars have been exchanged.
front_back('code') → 'eodc'
front_back('a') → 'a'
front_back('ab') → 'ba'
"""
if len(str)<=1: return str
return str[-1]+str[1:len(str)-1]+str[0]

67 changes: 67 additions & 0 deletions students/navidbahadoran/Lesson02/grid_printer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
title: grid_printer
Desc: print a grid with the same row and column number and each cell has the
size based on the user's input for the size
change log:
NBahadoran, 1/20/2018, Created grid_printer.py
"""

def grid(row,size):
"""
print the grid based on the size and the row input
:param row: No of row and column of the grid
:param size: size of each cells
:return: print the grid
"""
print_row(row, size)

for grid_row in range(row):

for cell_size in range(size):
print_beam(row,size)

print_row(row, size)



def print_beam(row,size):
"""
print the beam of the grid
:param row: No of | in the row minus 1
:param size: half of No of blank in the row
:return: print row which includes beams
"""
post = "|"
blank = " "
for i in range(row):
print(post, end=blank)
for j in range(size):
print(blank + blank, end="")
else:
print(post)

def print_row(row,size):
"""
print the row of the grid
:param row: No of + in the row minus 1
:param size: half of No of - in the row
:return: print row which includes + -
"""
plus = "+"
blank= " "
minus= "-"
for i in range(row):
print(plus, end=blank)
for j in range(size):
print(minus + blank, end="")
else:
print(plus)

try:
row=int(input("Enter the integer No of row of your grid: "))
size=int(input("Enter the integer No of size of your grid: "))
grid(row,size)
except Exception:
print("You entered the wrong input!")
print("Your input should be integer.")

16 changes: 16 additions & 0 deletions students/navidbahadoran/Lesson02/makes10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
title: makes10
change log:
NBahadoran, 1/19/2018, Created makes10.py
"""

def makes10(a, b):
"""
Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10.


makes10(9, 10) → True
makes10(9, 9) → False
makes10(1, 9) → True
"""
return (a + b == 10 or a == 10 or b == 10)
13 changes: 13 additions & 0 deletions students/navidbahadoran/Lesson02/missing_char.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@



def missing_char(str, n):
"""
Given a non-empty string and an int n, return a new string where the
char at index n has been removed. The value of n will be a valid
index of a char in the original string (i.e. n will be in the range 0..len(str)-1 inclusive).
missing_char('kitten', 1) → 'ktten'
missing_char('kitten', 0) → 'itten'
missing_char('kitten', 4) → 'kittn'
"""
return str[:n]+str[n+1:]
17 changes: 17 additions & 0 deletions students/navidbahadoran/Lesson02/near100.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
title: near100
change log:
NBahadoran, 1/19/2018, Created near100.py
"""


def near_hundred(n):
"""
Given an int n, return True if it is within 10 of 100 or 200.
Note: abs(num) computes the absolute value of a number.
near_hundred(93) → True
near_hundred(90) → True
near_hundred(89) → False
"""

return (abs(n-100)<=10 or abs(n-200)<=10)
19 changes: 19 additions & 0 deletions students/navidbahadoran/Lesson02/not_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
title: not_string
change log:
NBahadoran, 1/19/2018, Created not_string.py
"""
def not_string(str):
"""
Given a string, return a new string where "not " has been added to the front.
However, if the string already begins with "not", return the string unchanged.
not_string('candy') → 'not candy'
not_string('x') → 'not x'
not_string('not bad') → 'not bad'
"""
if "not".lower() in str[0:3]:
return str
return "not "+str

print(not_string("hello"))

18 changes: 18 additions & 0 deletions students/navidbahadoran/Lesson02/pos_neg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
title: pos_neg
change log:
NBahadoran, 1/19/2018, Created pos_neg.py
"""
def pos_neg(a, b, negative):
"""
Given 2 int values, return True if one is negative and one is positive.
Except if the parameter "negative" is True, then return True only if both are negative.
pos_neg(1, -1, False) → True
pos_neg(-1, 1, False) → True
pos_neg(-4, -5, True) → True
"""
if negative:
return (a<0 and b<0)
else:
return (a*b<0)
return False
Loading