Upload files to "basic programming/1st task"
This commit is contained in:
24
basic programming/1st task/10.py
Normal file
24
basic programming/1st task/10.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Q10
|
||||
|
||||
# Imports
|
||||
import math
|
||||
|
||||
# Get values from user
|
||||
x1 = float(input("Enter x-coordinate for point 1: "))
|
||||
y1 = float(input("Enter y-coordinate for point 1: "))
|
||||
x2 = float(input("Enter x-coordinate for point 2: "))
|
||||
y2 = float(input("Enter y-coordinate for point 2: "))
|
||||
x3 = float(input("Enter x-coordinate for point 3: "))
|
||||
y3 = float(input("Enter y-coordinate for point 3: "))
|
||||
|
||||
# Calculate the length of each side of the triangle
|
||||
side1 = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
||||
side2 = math.sqrt((x3 - x2)**2 + (y3 - y2)**2)
|
||||
side3 = math.sqrt((x1 - x3)**2 + (y1 - y3)**2)
|
||||
|
||||
|
||||
# Calculate the perimeter of the triangle
|
||||
perimeter = side1 + side2 + side3
|
||||
|
||||
# Print the perimeter
|
||||
print(f"The perimeter of the triangle is: {perimeter:.2f} units.")
|
||||
15
basic programming/1st task/6.py
Normal file
15
basic programming/1st task/6.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Q6
|
||||
|
||||
# Get value from user
|
||||
user_number = int(input("Input 4 digit number: "))
|
||||
|
||||
# Define variable
|
||||
sum_of_digits = 0
|
||||
|
||||
# Calculate sum of digits
|
||||
while user_number > 0:
|
||||
sum_of_digits += user_number%10
|
||||
user_number //= 10
|
||||
|
||||
# Print value
|
||||
print(f"The sum of the digits is: {sum_of_digits}")
|
||||
16
basic programming/1st task/7.py
Normal file
16
basic programming/1st task/7.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Q7
|
||||
|
||||
# Get values from user
|
||||
num1 = int(input("Enter 1st number:"))
|
||||
num2 = int(input("Enter 2nd number:"))
|
||||
num3 = int(input("Enter 3rd number:"))
|
||||
|
||||
# Determine smallest and largest
|
||||
minimum = min(num1, num2, num3)
|
||||
maximum = max(num1, num2, num3)
|
||||
|
||||
# Calculate sum
|
||||
sum = minimum + maximum
|
||||
|
||||
# Print result
|
||||
print(f"The sum of the smallest and largest number is: {sum}.")
|
||||
18
basic programming/1st task/8.py
Normal file
18
basic programming/1st task/8.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Q8
|
||||
|
||||
# Imports
|
||||
import math
|
||||
|
||||
# Get value from user
|
||||
number = float(input("Enter float with 5 or more decimal digits: "))
|
||||
|
||||
# Calculate ceiling and floor
|
||||
number_ceiling = math.ceil(number)
|
||||
number_floor = math.floor(number)
|
||||
|
||||
# Round number
|
||||
number_rounded = round(number, 2)
|
||||
|
||||
# Print results
|
||||
for variable in [number_floor, number_ceiling, number_rounded]:
|
||||
print(variable)
|
||||
17
basic programming/1st task/9.py
Normal file
17
basic programming/1st task/9.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Q9
|
||||
|
||||
# Imports
|
||||
import random
|
||||
import math
|
||||
|
||||
# Print header with proper formatting
|
||||
print(f"{'x':<10}{'y':<10}{'add':<10}{'subt':<10}"
|
||||
f"{'mult':<10}{'div':<10}{'sqrt':<10}")
|
||||
|
||||
# Generate random numbers
|
||||
x = random.randint(5,50)
|
||||
y = random.randint(5,50)
|
||||
|
||||
# Print values with proper formatting
|
||||
print(f"{x:<10}{y:<10}{x + y:<10}{x - y:<10}{x * y:<10}{x / y:<10.2f}"
|
||||
f"{(x**2 + y**2)**0.5:<10.2f}")
|
||||
Reference in New Issue
Block a user