30) Ikkilik sanoq sistemasidagi sonni X sanoq sistemasiga class satr():
o’tkazuvchi dasturni funksiya yordamida tuzing.
def ikkilikdan_x_sanoqga(ikkilik_son):
desimal_son = int(ikkilik_son, 2)
x_sanoq_son = ""
while desimal_son > 0:
qoldiq = desimal_son % 10
x_sanoq_son = str(qoldiq) + x_sanoq_son
desimal_son = desimal_son // 10
return x_sanoq_son
35)”input.txt” y4 nuqtalarning koordinatalari berilgan.Berilgan nuqtalardan
hosil qilingan eng katta kesma uzunligini “output.txt” fayliga yozsin
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))
31) Tasodifiy 10 ta [20,50] orasidagi sonni “output.txt”
faylga yozing va ular orasidagi tub sonlarni aniqlab “tub.txt”
faylga yozing. Agar “Output.txt” faylida tub son bo’lmasa
“tub.txt” faylga “tub son yo’q” yozuvi yozilsin
import random
output_file = open("output.txt", "w")
prime_file = open("tub.txt", "w")
for _ in range(10):
number = random.randint(20, 50)
output_file.write(str(number) + "\n")
if number < 2:
prime_file.write(str(number) + ": tub son emas\n") print(b)
continue
is_prime = True
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
is_prime = False
break
if is_prime:
prime_file.write(str(number) + ": tub son\n")
else:
prime_file.write(str(number) + ": tub son emas\n")
output_file.close()
prime_file.close()
35)”input.txt” y4 nuqtalarning koordinatalari berilgan.Berilgan nuqtalardan
hosil qilingan eng katta kesma uzunligini “output.txt” fayliga yozsin
Do'stlaringiz bilan baham: |