N butun son berilganu ning darajasi ekanligini aniqlang


with open('input.txt', 'r') as f


Download 134.94 Kb.
bet7/10
Sana22.06.2023
Hajmi134.94 Kb.
#1647477
1   2   3   4   5   6   7   8   9   10
Bog'liq
dasturlash shpargalka

with open('input.txt', 'r') as f:
x1, y1 = map(int, f.readline().split())
x2, y2 = map(int, f.readline().split())
x3, y3 = map(int, f.readline().split())
x4, y4 = map(int, f.readline().split())
distances = [((x1-x2)2 + (y1-y2)2)**0.5,
((x1-x3)2 + (y1-y3)2)**0.5,
((x1-x4)2 + (y1-y4)2)**0.5,
((x2-x3)2 + (y2-y3)2)**0.5,
((x2-x4)2 + (y2-y4)2)**0.5,
((x3-x4)2 + (y3-y4)2)**0.5]
max_distance = max(distances)
with open('output.txt', 'w') as f:
f.write(str(max_distance))


32) Tasodifiy 5 ta [30,40] orasidagi sonni “output.txt” faylga yozing va ular orasidagi juft sonlarni aniqlab “juft.txt” faylga yozing. Dasturni ishlatishda try... exsept
dan foydalaning
import random
output_file = open("output.txt", "w")
even_file = open("juft.txt", "w") for _ in range(5): try:
number = random.randint(30, 40)
output_file.write(str(number) + "\n")
if number % 2 == 0: even_file.write(str(number) + "\n")
except:
continue output_file.close()
even_file.close()
36) “input.txt” faylida x1,y1 x2,y2 nuqtalarning koordinatalari berilgan. Berilgan
nuqtalardan hosil qilingan kesma uzunligini “output.txt” fayl yozsin.
import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) 2 + (y2 - y1) 2)
try:
with open("input.txt", "r") as input_file:
coordinates = input_file.read().split()

x1, y1 = map(int, coordinates[0].split(","))
x2, y2 = map(int, coordinates[1].split(","))

distance = calculate_distance(x1, y1, x2, y2)

with open("output.txt", "w") as output_file:
output_file.write(str(distance))

Download 134.94 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling