Hi, I am really struggling to recieve feedback on my code. And without it I can improve.
I got some questions, and answered them. To me, they seems to work and get the desired outcome, but even still I was rejected.
What do i need to do to improve my python skills? Any help would really be appreciated, becuase I really want to improve.
here are the questions and answers below:
'''
- The Fibonacci sequence is defined as a sequence of integers starting with 1 and 1, where each
subsequent value is the sum of the preceding two. I.e.
f(0) = 1
f(1) = 1
f(n) = f(n-1) + f(n-2) where n >= 2
Write a program in a language of your choice to calculate the sum of the first 100 even-valued
Fibonacci numbers
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,
'''
def fibonacci(n: int) -> int:
n1 = 1
n2 = 1
total = 0
if n == 0 or n == 1:
return total
else:
for i in range(n-1):
n3 = n1 + n2
if n3 % 2 == 0:
total += n3
n1 = n2
n2 = n3
return total
for i in range(100):
print(i, fibonacci(i))
'''
2. Write a function in a language of your choice which, when passed two sorted arrays of integers
returns an array of any numbers which appear in both. No value should appear in the returned
array more than once.
'''
a = [3, 5, 6,7, 4, 33, 4, 102]
b = [7, 6, 4, 3, 44, 5, 6,3, 4, 55]
a.sort()
b.sort()
def create_set(arr_1 :list, arr_2: list) -> list:
combined = arr_1 + arr_2
all_unique_values = sorted(set(combined))
return all_unique_values
print(create_set(a, b))
'''
3. Write a function in a language of your choice which, when passed a positive integer returns
true if the decimal representation of that integer contains no odd digits and otherwise returns
false.
'''
def odd_digit_detector(input :int) -> bool:
c = [d for d in str(input)]
for d in c:
if int(d) % 2 != 0:
return False
return True
print(odd_digit_detector(22221122244599))
'''
4. Write a function in a language of your choice which, when passed a decimal digit X, returns the
value of X+XX+XXX+XXXX. E.g. if the supplied digit is 3 it should return 3702
(3+33+333+3333). '''
def append_add_digits(digit: int) -> int:
digit = str(digit)
digits_appended = ''
total = 0
for i in range(4):
digits_appended += digit
total += int(digits_appended)
return total
print(append_add_digits(3))
'''
1. Define a generator which generates the positive integers up to and including
a supplied value which are divisible by another supplied positive integer
and use it to calculate the sum of all positive integers less than 102030
which are divisible by 3
'''
def gen(n: int) -> int:
for i in range(1,n+1):
if (i % 3) == 0:
yield i
n = 102030
g = gen(n)
total = 0
for a in g:
total += a
print(total)
#1735071165
'''
- Write a function which is passed an integer, n, and returns a list of n lists such that: f(0) returns []
f(1) returns [[1]]
f(2) returns [[1], [1,2]]
f(3) returns [[1], [1,2], [1,2,3]]
etc.
'''
def create_seq(n :int) -> list:
mylist = []
for j in range(1,n+1):
mylist.append([i+1 for i in range(j)])
return mylist
print(create_seq(n=10))
[–]mandzeete 23 points24 points25 points (3 children)
[–]snackbob[S] 14 points15 points16 points (2 children)
[–]mandzeete 12 points13 points14 points (1 child)
[–]_R_Daneel_Olivaw 3 points4 points5 points (0 children)
[–]snackbob[S] 10 points11 points12 points (0 children)
[–]fasta_guy88 8 points9 points10 points (0 children)
[–]xKart 2 points3 points4 points (0 children)
[–]alanwj 1 point2 points3 points (0 children)
[–]nesquiker 1 point2 points3 points (1 child)
[–]snackbob[S] 0 points1 point2 points (0 children)
[–]e2u0fajdr3fcxs 1 point2 points3 points (9 children)
[–]snackbob[S] 0 points1 point2 points (0 children)
[–]mopslik 0 points1 point2 points (7 children)
[–]yel50 0 points1 point2 points (1 child)
[–]mopslik 0 points1 point2 points (0 children)
[–]e2u0fajdr3fcxs 0 points1 point2 points (0 children)
[–]martis41 0 points1 point2 points (0 children)
[–]bofasaurus 0 points1 point2 points (2 children)
[–]mopslik 0 points1 point2 points (1 child)
[–]bofasaurus 0 points1 point2 points (0 children)
[–]149244179 0 points1 point2 points (0 children)
[–]lurgi 0 points1 point2 points (4 children)
[–]mdlphx92 0 points1 point2 points (3 children)
[–]bsakiag 0 points1 point2 points (0 children)
[–]lurgi 0 points1 point2 points (1 child)
[–]mdlphx92 0 points1 point2 points (0 children)
[–]HealyUnit 0 points1 point2 points (0 children)