"""
ASSIGNMENT RULES
- You are strictly forbidden to share answers with your course mates.
- You are not allowed to search for answers on the Internet. You are not
allowed to ask for answers in forums or other online communication systems.
- Note that, when you find an answer on the web, somebody else will also find
it and use it. This means, both of you will submit the exact same answer.
This, then, means cheating, no matter you know the other person or not.
- If your answers are similar to some other student's answers, you will
receive -100 points from the assignment. We don't care whether you know
the other person or not, we don't care whether he/she is your friend or not,
we don't care who delivered and who received. Both parties get -100 points.
- You are not allowed to import any packages. If there are any imports in your
submission, we will remove them before grading.
- If your file doesn't compile, then you receive 0. Make sure that your
indentation and syntax is correct.
- Do not change the below function definitions. In other words, DO NOT CHANGE
the function names and the parameters of the functions. You are only allowed
to write code within the function scope.
- Do not print anything on the screen unless you are asked to. Some questions
require you to RETURN a value. Printing that value on the screen is not equal
to returning the value.
- Do not submit any testing code.
DO NOT FORGET TO FILL THE LINES BELOW:
My full name : _______________
My student ID : _______________
My department : _______________
My piazza email : _______________
"""
"""
Question 1: (30 points)
Write a function named `pyramid(s)` that takes a string as its input
and PRINTs out a pyramid on the screen based on this string. For example,
when called as `pyramid("BURKAY")` it will print:
B
UU
RRR
KKKK
AAAAA
YYYYYY
"""
def pyramid(s):
for i in range(len(s)):
print(s[i]*(i+1))
"""
Question 2: (35 Points)
Two integers are relatively prime (or coprime) if there is no integer greater
than one that divides them both (that is, their greatest common divisor is 1).
Write a function that takes two integers and returns True if the integers have
a common divisor that is different than 1 (if they are not relatively prime),
otherwise returns False.
For example, notRelPrime(3,5) returns False, whereas notRelPrime(8,12) returns
True. Because, 3 and 5 have only one common divisor, which is 1, whereas 8 and
12 are both divisible by 1, 2 and 4.
"""
def notRelPrime(a,b):
for i in range(2, max(3,min(a//2,b//2) + 1)):
if a % i == 0 and b % i == 0:
return True
return False
"""
Question 3: (35 points)
Write a function that computes and RETURNs the following recursive value:
A(n) = A(n-1) + 1 , if n is odd
A(n-1) + 2 , if n is even
0 , if n is 1
"""
def recursion(n):
if n == 1:
return 0
elif n % 2 == 0:
return recursion(n-1) + 2
else:
return recursion(n-1) + 1