|
3-Amaliy ishi Bajardi: Turaqulov s tekshirdi: Saidov s variant 12
|
Sana | 06.07.2024 | Hajmi | 143,35 Kb. | | #266775 |
Bog'liq dasturlash 3
O’zbekiston Respublikasi Axborot Texnologiyalari va kommunikatsiyalarini rivojlantirish vazirligi
Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti.
Dasturlash II
dan
3-Amaliy ishi
Bajardi: Turaqulov S
Tekshirdi: Saidov S
Variant - 12
Formada a[N][M] massiv elementlarini [-1000; 500] oraliqdagi tasodifiy sonlar bilan to’ldiring. N va M ni TextBox komponetalari yordamida kiriting. Massivni dataGridWiew komponentasiga joylashtiring. Massivni manfiy elementlarini ularning absolyut qiymati bilan almashtiring va almashtirishlar sonini label komponentasida chiqaring.
import tkinter as tk
from tkinter import ttk
import numpy as np
def create_array():
try:
N = int(entry_n.get())
M = int(entry_m.get())
except ValueError:
label_result.config(text="Iltimos, N va M qiymatlarini to'g'ri kiriting.")
return
array = np.random.randint(-1000, 501, size=(N, M))
for i in tree.get_children():
tree.delete(i)
for row in array:
tree.insert("", "end", values=tuple(row))
negative_count = 0
for i in range(N):
for j in range(M):
if array[i, j] < 0:
array[i, j] = abs(array[i, j])
negative_count += 1
label_result.config(text=f"Almashtirilgan manfiy elementlar soni: {negative_count}")
for i in tree.get_children():
tree.delete(i)
for row in array:
tree.insert("", "end", values=tuple(row))
root = tk.Tk()
root.title("Massiv yaratish va o'zgartirish")
frame = tk.Frame(root)
frame.pack(pady=10)
label_n = tk.Label(frame, text="N:")
label_n.grid(row=0, column=0, padx=5, pady=5)
entry_n = tk.Entry(frame)
entry_n.grid(row=0, column=1, padx=5, pady=5)
label_m = tk.Label(frame, text="M:")
label_m.grid(row=1, column=0, padx=5, pady=5)
entry_m = tk.Entry(frame)
entry_m.grid(row=1, column=1, padx=5, pady=5)
button_create = tk.Button(frame, text="Massiv yaratish", command=create_array)
button_create.grid(row=2, column=0, columnspan=2, padx=5, pady=5)
tree = ttk.Treeview(root, columns=(1, 2, 3), show="headings", height=10)
tree.pack(pady=10)
label_result = tk.Label(root, text="")
label_result.pack(pady=5)
root.mainloop()
|
| |