assign
This commit is contained in:
parent
a47ef094af
commit
c516afc400
13 changed files with 240 additions and 184 deletions
|
|
@ -1,33 +1,29 @@
|
|||
import math
|
||||
def countdown(n):
|
||||
while n > 0:
|
||||
print(f"Countdown: {n}")
|
||||
n -= 1
|
||||
print("Blast off!")
|
||||
|
||||
def circle_area(radius):
|
||||
return math.pi * radius ** 2
|
||||
|
||||
def circle_circumference(radius):
|
||||
return 2 * math.pi * radius
|
||||
|
||||
def solve_quadratic(a, b, c):
|
||||
discriminant = b ** 2 - 4 * a * c
|
||||
def sum_until_negative():
|
||||
total = 0
|
||||
count = 0
|
||||
inputs = [5, 3, 8, -1, 4, 2]
|
||||
|
||||
if discriminant < 0:
|
||||
return None, None
|
||||
elif discriminant == 0:
|
||||
x = -b / (2 * a)
|
||||
return x, x
|
||||
for value in inputs:
|
||||
if value < 0:
|
||||
break
|
||||
total += value
|
||||
count += 1
|
||||
|
||||
if count > 0:
|
||||
average = total / count
|
||||
return total, average
|
||||
else:
|
||||
x1 = (-b + math.sqrt(discriminant)) / (2 * a)
|
||||
x2 = (-b - math.sqrt(discriminant)) / (2 * a)
|
||||
return x1, x2
|
||||
return 0, 0
|
||||
|
||||
print(f"Circle with radius 5:")
|
||||
print(f" Area: {circle_area(5):.2f}")
|
||||
print(f" Circumference: {circle_circumference(5):.2f}")
|
||||
print("Countdown from 5:")
|
||||
countdown(5)
|
||||
|
||||
print(f"\nQuadratic 2x² + 5x - 3 = 0:")
|
||||
x1, x2 = solve_quadratic(2, 5, -3)
|
||||
print(f" Solutions: {x1:.2f}, {x2:.2f}")
|
||||
|
||||
print(f"\nQuadratic x² + 1 = 0:")
|
||||
x1, x2 = solve_quadratic(1, 0, 1)
|
||||
if x1 is None:
|
||||
print(" No real solutions")
|
||||
print("\nSum until negative:")
|
||||
total, avg = sum_until_negative()
|
||||
print(f"Total: {total}, Average: {avg:.2f}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue