Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adam atamer #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
31 changes: 12 additions & 19 deletions Buggggggs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Fibbonacci sequence calculation
# Fibonacci: sequence calculation
a, b, n = 0, 1, 10
fibonacci = []
for i in range(n)
for i in range(n):
fibonacci.append(a)
a, b = b, a + b
pritn(f"Fibbonacci sequence of {n} numbers: {fibonacci}")
print(f"Fibonacci sequence of {n} numbers: {fibonacci}")

# Find minimum and maximum in a list
numbers = [3, 5, 1, 10, 2, 7, 6, 4, 8, 9]
Expand Down Expand Up @@ -58,12 +58,12 @@
vowels = "aeiou"
vowel_count = 0
for char in string:
if char in vowel:
if char in vowels:
vowel_count += 1
print(f"Number of vowels in the string: {vowel_count}")

# Palindrome check
word = "racecar"
word = "race car"
is_palindrome = True
for i in range(len(word) // 2):
if word[i] != word[-i - 1]:
Expand All @@ -79,7 +79,7 @@
sum_elements = 0
for num in number:
if not num > 0:
sum_elements += num
sum_elements=num
print(f"Sum of elements: {sum_elements}")

# Factorial calculation
Expand All @@ -96,10 +96,9 @@

# Checking if a number is even or odd
number = 15
if number%2 = 0:
print(f"{number} is even")
else
print(f"{number} is odd")
if number%2 : 0
print(f"{number} is even")
print(f"{number} is odd")


# Appending four elements to the end of the list
Expand All @@ -120,14 +119,8 @@

# Count even numbers from Zero to 50
count = 0
while True:
if count == 51:
break
count += 2


# Sum of first n natural numbers
n = 10
while not count == 51:
count = 2
sum_natural = 0
for i in range(n):
sum_natural += i
Expand All @@ -152,7 +145,7 @@

# Check if a number is a perfect square
num = 25
if int(num 0.5) * int(num 0.5) = num:
if int num 0.5 * int(num 0.5) = num
print(f"{num} is a perfect square")
else:
print(f"{num} is not a perfect square")
Expand Down
30 changes: 30 additions & 0 deletions Perimeter of a Polygon .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import math

def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def compute_polygon_perimeter():
points = []

x = input("Enter the x part of the coordinate: ")
if x == "":
return 0.0
y = float(input("Enter the y part of the coordinate: "))
points.append((float(x), y))

while True:
x = input("Enter the x part of the coordinate: (blank to quit): ")
if x == "":
break
y = float(input("Enter the y part of the coordinate: "))
points.append((float(x), y))

perimeter = 0.0
for i in range(len(points)):
next_i = (i + 1) % len(points)
perimeter += calculate_distance(points[i][0], points[i][1], points[next_i][0], points[next_i][1])

return perimeter

perimeter = compute_polygon_perimeter()
print(f"The perimeter of that polygon is {perimeter:.5f}")
20 changes: 20 additions & 0 deletions Remove Outliers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def remove_extremes(sorted_list, n):
if len(sorted_list) < 4:
return "Error: Please enter at least 4 values."


sorted_list = sorted_list[:-n]

sorted_list = sorted_list[n:]


return sorted_list


sorted_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
n = 3
print(remove_extremes(sorted_list, n))


short_list = [1, 2, 3]
print(remove_extremes(short_list, n))
19 changes: 19 additions & 0 deletions birnary number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def binary_to_decimal(binary_number):
decimal_number = 0
binary_digits = list(binary_number)
binary_digits.reverse()

for i in range(len(binary_digits)):
digit = int(binary_digits[i])
if digit != 0 and digit != 1:
raise ValueError("Invalid binary number")
decimal_number += digit * (2 ** i)

return decimal_number

binary_number = input("Enter a binary number: ")
try:
decimal_equivalent = binary_to_decimal(binary_number)
print(f"The decimal equivalent of {binary_number} is: {decimal_equivalent}")
except ValueError as e:
print(str(e))
12 changes: 12 additions & 0 deletions chess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def determine_square_color(position):
column_index = ord(position[0].lower()) - 97
row_index = int(position[1]) - 1

if (column_index + row_index) % 2 == 0:
return "white"
else:
return "black"

position = input("Enter a chess position (e.g., 'a1', 'd5'): ")
square_color = determine_square_color(position)
print(f"The square at position {position} is {square_color}.")
17 changes: 17 additions & 0 deletions cumsum .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def cumsum(numbers):
cumulative_sum = [numbers[0]] if numbers else []

for i in range(1, len(numbers)):
next_element = numbers[i] + cumulative_sum[-1]

cumulative_sum.append(next_element)

return cumulative_sum


t = [1, 2, 3]
print(cumsum(t))


another_list = [1, 5, 7, 2, 9]
print(cumsum(another_list))
24 changes: 24 additions & 0 deletions formating a list .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def format_list(lst):
if not lst:
return ""
if len(lst) == 1:
return lst[0]


items_except_last = ", ".join(lst[:-1])

return f"{items_except_last}, and {lst[-1]}"


my_list = ["apple", "banana", "cherry", "date"]
print(format_list(my_list))

another_list = ["item1", "item2", "item3", "item4", "item5", "item6"]
print(format_list(another_list))


empty_list = []
print(format_list(empty_list))

single_item_list = ["single item"]
print(format_list(single_item_list))
18 changes: 18 additions & 0 deletions sorted numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def is_sorted(lst):
if not lst:
return True

if len(lst) == 1:
return True

for i in range(1, len(lst)):
if lst[i] < lst[i - 1]:
return False

return True

print(is_sorted([]))
print(is_sorted([1]))
print(is_sorted([1, 2, 3]))
print(is_sorted([1, 3, 2]))
print(is_sorted([3, 2, 1]))