From 8e587fac7f7f8530482f2e3dfd8e946360b7853a Mon Sep 17 00:00:00 2001 From: OptimAssaSin <148183548+OptimAssaSin@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:29:38 +0530 Subject: [PATCH 01/62] Changes to Sub-Folder names in C++ --- C++/{Advanced => Hard}/1.cpp | 0 C++/{Advanced => Hard}/10.cpp | 0 C++/{Advanced => Hard}/11.cpp | 0 C++/{Advanced => Hard}/12.cpp | 0 C++/{Advanced => Hard}/13.cpp | 0 C++/{Advanced => Hard}/14.cpp | 0 C++/{Advanced => Hard}/15.cpp | 0 C++/{Advanced => Hard}/16.cpp | 0 C++/{Advanced => Hard}/17.cpp | 0 C++/{Advanced => Hard}/18.cpp | 0 C++/{Advanced => Hard}/19.cpp | 0 C++/{Advanced => Hard}/2.cpp | 0 C++/{Advanced => Hard}/20.cpp | 0 C++/{Advanced => Hard}/21.cpp | 0 C++/{Advanced => Hard}/22.cpp | 0 C++/{Advanced => Hard}/23.cpp | 0 C++/{Advanced => Hard}/24.cpp | 0 C++/{Advanced => Hard}/25.cpp | 0 C++/{Advanced => Hard}/26.cpp | 0 C++/{Advanced => Hard}/27.cpp | 0 C++/{Advanced => Hard}/28.cpp | 0 C++/{Advanced => Hard}/29.cpp | 0 C++/{Advanced => Hard}/3.cpp | 0 C++/{Advanced => Hard}/30.cpp | 0 C++/{Advanced => Hard}/31.cpp | 0 C++/{Advanced => Hard}/32.cpp | 0 C++/{Advanced => Hard}/33.cpp | 0 C++/{Advanced => Hard}/34.cpp | 0 C++/{Advanced => Hard}/35.cpp | 0 C++/{Advanced => Hard}/36.cpp | 0 C++/{Advanced => Hard}/37.cpp | 0 C++/{Advanced => Hard}/38.cpp | 0 C++/{Advanced => Hard}/39.cpp | 0 C++/{Advanced => Hard}/4.cpp | 0 C++/{Advanced => Hard}/40.cpp | 0 C++/{Advanced => Hard}/41.cpp | 0 C++/{Advanced => Hard}/42.cpp | 0 C++/{Advanced => Hard}/43.cpp | 0 C++/{Advanced => Hard}/44.cpp | 0 C++/{Advanced => Hard}/45.cpp | 0 C++/{Advanced => Hard}/46.cpp | 0 C++/{Advanced => Hard}/47.cpp | 0 C++/{Advanced => Hard}/48.cpp | 0 C++/{Advanced => Hard}/49.cpp | 0 C++/{Advanced => Hard}/5.cpp | 0 C++/{Advanced => Hard}/50.cpp | 0 C++/{Advanced => Hard}/6.cpp | 0 C++/{Advanced => Hard}/7.cpp | 0 C++/{Advanced => Hard}/8.cpp | 0 C++/{Advanced => Hard}/9.cpp | 0 C++/{Intermediate => Medium}/1.cpp | 0 C++/{Intermediate => Medium}/10.cpp | 0 C++/{Intermediate => Medium}/11.cpp | 0 C++/{Intermediate => Medium}/12.cpp | 0 C++/{Intermediate => Medium}/13.cpp | 0 C++/{Intermediate => Medium}/14.cpp | 0 C++/{Intermediate => Medium}/15.cpp | 0 C++/{Intermediate => Medium}/16.cpp | 0 C++/{Intermediate => Medium}/17.cpp | 0 C++/{Intermediate => Medium}/18.cpp | 0 C++/{Intermediate => Medium}/19.cpp | 0 C++/{Intermediate => Medium}/2.cpp | 0 C++/{Intermediate => Medium}/20.cpp | 0 C++/{Intermediate => Medium}/21.cpp | 0 C++/{Intermediate => Medium}/22.cpp | 0 C++/{Intermediate => Medium}/23.cpp | 0 C++/{Intermediate => Medium}/24.cpp | 0 C++/{Intermediate => Medium}/25.cpp | 0 C++/{Intermediate => Medium}/26.cpp | 0 C++/{Intermediate => Medium}/27.cpp | 0 C++/{Intermediate => Medium}/28.cpp | 0 C++/{Intermediate => Medium}/29.cpp | 0 C++/{Intermediate => Medium}/3.cpp | 0 C++/{Intermediate => Medium}/30.cpp | 0 C++/{Intermediate => Medium}/31.cpp | 0 C++/{Intermediate => Medium}/32.cpp | 0 C++/{Intermediate => Medium}/33.cpp | 0 C++/{Intermediate => Medium}/34.cpp | 0 C++/{Intermediate => Medium}/35.cpp | 0 C++/{Intermediate => Medium}/36.cpp | 0 C++/{Intermediate => Medium}/37.cpp | 0 C++/{Intermediate => Medium}/38.cpp | 0 C++/{Intermediate => Medium}/39.cpp | 0 C++/{Intermediate => Medium}/4.cpp | 0 C++/{Intermediate => Medium}/40.cpp | 0 C++/{Intermediate => Medium}/41.cpp | 0 C++/{Intermediate => Medium}/42.cpp | 0 C++/{Intermediate => Medium}/43.cpp | 0 C++/{Intermediate => Medium}/44.cpp | 0 C++/{Intermediate => Medium}/45.cpp | 0 C++/{Intermediate => Medium}/46.cpp | 0 C++/{Intermediate => Medium}/47.cpp | 0 C++/{Intermediate => Medium}/48.cpp | 0 C++/{Intermediate => Medium}/49.cpp | 0 C++/{Intermediate => Medium}/5.cpp | 0 C++/{Intermediate => Medium}/50.cpp | 0 C++/{Intermediate => Medium}/51.cpp | 0 C++/{Intermediate => Medium}/52.cpp | 0 C++/{Intermediate => Medium}/53.cpp | 0 C++/{Intermediate => Medium}/54.cpp | 0 C++/{Intermediate => Medium}/55.cpp | 0 C++/{Intermediate => Medium}/56.cpp | 0 C++/{Intermediate => Medium}/57.cpp | 0 C++/{Intermediate => Medium}/58.cpp | 0 C++/{Intermediate => Medium}/59.cpp | 0 C++/{Intermediate => Medium}/6.cpp | 0 C++/{Intermediate => Medium}/60.cpp | 0 C++/{Intermediate => Medium}/61.cpp | 0 C++/{Intermediate => Medium}/62.cpp | 0 C++/{Intermediate => Medium}/63.cpp | 0 C++/{Intermediate => Medium}/64.cpp | 0 C++/{Intermediate => Medium}/65.cpp | 0 C++/{Intermediate => Medium}/66.cpp | 0 C++/{Intermediate => Medium}/7.cpp | 0 C++/{Intermediate => Medium}/8.cpp | 0 C++/{Intermediate => Medium}/9.cpp | 0 116 files changed, 0 insertions(+), 0 deletions(-) rename C++/{Advanced => Hard}/1.cpp (100%) rename C++/{Advanced => Hard}/10.cpp (100%) rename C++/{Advanced => Hard}/11.cpp (100%) rename C++/{Advanced => Hard}/12.cpp (100%) rename C++/{Advanced => Hard}/13.cpp (100%) rename C++/{Advanced => Hard}/14.cpp (100%) rename C++/{Advanced => Hard}/15.cpp (100%) rename C++/{Advanced => Hard}/16.cpp (100%) rename C++/{Advanced => Hard}/17.cpp (100%) rename C++/{Advanced => Hard}/18.cpp (100%) rename C++/{Advanced => Hard}/19.cpp (100%) rename C++/{Advanced => Hard}/2.cpp (100%) rename C++/{Advanced => Hard}/20.cpp (100%) rename C++/{Advanced => Hard}/21.cpp (100%) rename C++/{Advanced => Hard}/22.cpp (100%) rename C++/{Advanced => Hard}/23.cpp (100%) rename C++/{Advanced => Hard}/24.cpp (100%) rename C++/{Advanced => Hard}/25.cpp (100%) rename C++/{Advanced => Hard}/26.cpp (100%) rename C++/{Advanced => Hard}/27.cpp (100%) rename C++/{Advanced => Hard}/28.cpp (100%) rename C++/{Advanced => Hard}/29.cpp (100%) rename C++/{Advanced => Hard}/3.cpp (100%) rename C++/{Advanced => Hard}/30.cpp (100%) rename C++/{Advanced => Hard}/31.cpp (100%) rename C++/{Advanced => Hard}/32.cpp (100%) rename C++/{Advanced => Hard}/33.cpp (100%) rename C++/{Advanced => Hard}/34.cpp (100%) rename C++/{Advanced => Hard}/35.cpp (100%) rename C++/{Advanced => Hard}/36.cpp (100%) rename C++/{Advanced => Hard}/37.cpp (100%) rename C++/{Advanced => Hard}/38.cpp (100%) rename C++/{Advanced => Hard}/39.cpp (100%) rename C++/{Advanced => Hard}/4.cpp (100%) rename C++/{Advanced => Hard}/40.cpp (100%) rename C++/{Advanced => Hard}/41.cpp (100%) rename C++/{Advanced => Hard}/42.cpp (100%) rename C++/{Advanced => Hard}/43.cpp (100%) rename C++/{Advanced => Hard}/44.cpp (100%) rename C++/{Advanced => Hard}/45.cpp (100%) rename C++/{Advanced => Hard}/46.cpp (100%) rename C++/{Advanced => Hard}/47.cpp (100%) rename C++/{Advanced => Hard}/48.cpp (100%) rename C++/{Advanced => Hard}/49.cpp (100%) rename C++/{Advanced => Hard}/5.cpp (100%) rename C++/{Advanced => Hard}/50.cpp (100%) rename C++/{Advanced => Hard}/6.cpp (100%) rename C++/{Advanced => Hard}/7.cpp (100%) rename C++/{Advanced => Hard}/8.cpp (100%) rename C++/{Advanced => Hard}/9.cpp (100%) rename C++/{Intermediate => Medium}/1.cpp (100%) rename C++/{Intermediate => Medium}/10.cpp (100%) rename C++/{Intermediate => Medium}/11.cpp (100%) rename C++/{Intermediate => Medium}/12.cpp (100%) rename C++/{Intermediate => Medium}/13.cpp (100%) rename C++/{Intermediate => Medium}/14.cpp (100%) rename C++/{Intermediate => Medium}/15.cpp (100%) rename C++/{Intermediate => Medium}/16.cpp (100%) rename C++/{Intermediate => Medium}/17.cpp (100%) rename C++/{Intermediate => Medium}/18.cpp (100%) rename C++/{Intermediate => Medium}/19.cpp (100%) rename C++/{Intermediate => Medium}/2.cpp (100%) rename C++/{Intermediate => Medium}/20.cpp (100%) rename C++/{Intermediate => Medium}/21.cpp (100%) rename C++/{Intermediate => Medium}/22.cpp (100%) rename C++/{Intermediate => Medium}/23.cpp (100%) rename C++/{Intermediate => Medium}/24.cpp (100%) rename C++/{Intermediate => Medium}/25.cpp (100%) rename C++/{Intermediate => Medium}/26.cpp (100%) rename C++/{Intermediate => Medium}/27.cpp (100%) rename C++/{Intermediate => Medium}/28.cpp (100%) rename C++/{Intermediate => Medium}/29.cpp (100%) rename C++/{Intermediate => Medium}/3.cpp (100%) rename C++/{Intermediate => Medium}/30.cpp (100%) rename C++/{Intermediate => Medium}/31.cpp (100%) rename C++/{Intermediate => Medium}/32.cpp (100%) rename C++/{Intermediate => Medium}/33.cpp (100%) rename C++/{Intermediate => Medium}/34.cpp (100%) rename C++/{Intermediate => Medium}/35.cpp (100%) rename C++/{Intermediate => Medium}/36.cpp (100%) rename C++/{Intermediate => Medium}/37.cpp (100%) rename C++/{Intermediate => Medium}/38.cpp (100%) rename C++/{Intermediate => Medium}/39.cpp (100%) rename C++/{Intermediate => Medium}/4.cpp (100%) rename C++/{Intermediate => Medium}/40.cpp (100%) rename C++/{Intermediate => Medium}/41.cpp (100%) rename C++/{Intermediate => Medium}/42.cpp (100%) rename C++/{Intermediate => Medium}/43.cpp (100%) rename C++/{Intermediate => Medium}/44.cpp (100%) rename C++/{Intermediate => Medium}/45.cpp (100%) rename C++/{Intermediate => Medium}/46.cpp (100%) rename C++/{Intermediate => Medium}/47.cpp (100%) rename C++/{Intermediate => Medium}/48.cpp (100%) rename C++/{Intermediate => Medium}/49.cpp (100%) rename C++/{Intermediate => Medium}/5.cpp (100%) rename C++/{Intermediate => Medium}/50.cpp (100%) rename C++/{Intermediate => Medium}/51.cpp (100%) rename C++/{Intermediate => Medium}/52.cpp (100%) rename C++/{Intermediate => Medium}/53.cpp (100%) rename C++/{Intermediate => Medium}/54.cpp (100%) rename C++/{Intermediate => Medium}/55.cpp (100%) rename C++/{Intermediate => Medium}/56.cpp (100%) rename C++/{Intermediate => Medium}/57.cpp (100%) rename C++/{Intermediate => Medium}/58.cpp (100%) rename C++/{Intermediate => Medium}/59.cpp (100%) rename C++/{Intermediate => Medium}/6.cpp (100%) rename C++/{Intermediate => Medium}/60.cpp (100%) rename C++/{Intermediate => Medium}/61.cpp (100%) rename C++/{Intermediate => Medium}/62.cpp (100%) rename C++/{Intermediate => Medium}/63.cpp (100%) rename C++/{Intermediate => Medium}/64.cpp (100%) rename C++/{Intermediate => Medium}/65.cpp (100%) rename C++/{Intermediate => Medium}/66.cpp (100%) rename C++/{Intermediate => Medium}/7.cpp (100%) rename C++/{Intermediate => Medium}/8.cpp (100%) rename C++/{Intermediate => Medium}/9.cpp (100%) diff --git a/C++/Advanced/1.cpp b/C++/Hard/1.cpp similarity index 100% rename from C++/Advanced/1.cpp rename to C++/Hard/1.cpp diff --git a/C++/Advanced/10.cpp b/C++/Hard/10.cpp similarity index 100% rename from C++/Advanced/10.cpp rename to C++/Hard/10.cpp diff --git a/C++/Advanced/11.cpp b/C++/Hard/11.cpp similarity index 100% rename from C++/Advanced/11.cpp rename to C++/Hard/11.cpp diff --git a/C++/Advanced/12.cpp b/C++/Hard/12.cpp similarity index 100% rename from C++/Advanced/12.cpp rename to C++/Hard/12.cpp diff --git a/C++/Advanced/13.cpp b/C++/Hard/13.cpp similarity index 100% rename from C++/Advanced/13.cpp rename to C++/Hard/13.cpp diff --git a/C++/Advanced/14.cpp b/C++/Hard/14.cpp similarity index 100% rename from C++/Advanced/14.cpp rename to C++/Hard/14.cpp diff --git a/C++/Advanced/15.cpp b/C++/Hard/15.cpp similarity index 100% rename from C++/Advanced/15.cpp rename to C++/Hard/15.cpp diff --git a/C++/Advanced/16.cpp b/C++/Hard/16.cpp similarity index 100% rename from C++/Advanced/16.cpp rename to C++/Hard/16.cpp diff --git a/C++/Advanced/17.cpp b/C++/Hard/17.cpp similarity index 100% rename from C++/Advanced/17.cpp rename to C++/Hard/17.cpp diff --git a/C++/Advanced/18.cpp b/C++/Hard/18.cpp similarity index 100% rename from C++/Advanced/18.cpp rename to C++/Hard/18.cpp diff --git a/C++/Advanced/19.cpp b/C++/Hard/19.cpp similarity index 100% rename from C++/Advanced/19.cpp rename to C++/Hard/19.cpp diff --git a/C++/Advanced/2.cpp b/C++/Hard/2.cpp similarity index 100% rename from C++/Advanced/2.cpp rename to C++/Hard/2.cpp diff --git a/C++/Advanced/20.cpp b/C++/Hard/20.cpp similarity index 100% rename from C++/Advanced/20.cpp rename to C++/Hard/20.cpp diff --git a/C++/Advanced/21.cpp b/C++/Hard/21.cpp similarity index 100% rename from C++/Advanced/21.cpp rename to C++/Hard/21.cpp diff --git a/C++/Advanced/22.cpp b/C++/Hard/22.cpp similarity index 100% rename from C++/Advanced/22.cpp rename to C++/Hard/22.cpp diff --git a/C++/Advanced/23.cpp b/C++/Hard/23.cpp similarity index 100% rename from C++/Advanced/23.cpp rename to C++/Hard/23.cpp diff --git a/C++/Advanced/24.cpp b/C++/Hard/24.cpp similarity index 100% rename from C++/Advanced/24.cpp rename to C++/Hard/24.cpp diff --git a/C++/Advanced/25.cpp b/C++/Hard/25.cpp similarity index 100% rename from C++/Advanced/25.cpp rename to C++/Hard/25.cpp diff --git a/C++/Advanced/26.cpp b/C++/Hard/26.cpp similarity index 100% rename from C++/Advanced/26.cpp rename to C++/Hard/26.cpp diff --git a/C++/Advanced/27.cpp b/C++/Hard/27.cpp similarity index 100% rename from C++/Advanced/27.cpp rename to C++/Hard/27.cpp diff --git a/C++/Advanced/28.cpp b/C++/Hard/28.cpp similarity index 100% rename from C++/Advanced/28.cpp rename to C++/Hard/28.cpp diff --git a/C++/Advanced/29.cpp b/C++/Hard/29.cpp similarity index 100% rename from C++/Advanced/29.cpp rename to C++/Hard/29.cpp diff --git a/C++/Advanced/3.cpp b/C++/Hard/3.cpp similarity index 100% rename from C++/Advanced/3.cpp rename to C++/Hard/3.cpp diff --git a/C++/Advanced/30.cpp b/C++/Hard/30.cpp similarity index 100% rename from C++/Advanced/30.cpp rename to C++/Hard/30.cpp diff --git a/C++/Advanced/31.cpp b/C++/Hard/31.cpp similarity index 100% rename from C++/Advanced/31.cpp rename to C++/Hard/31.cpp diff --git a/C++/Advanced/32.cpp b/C++/Hard/32.cpp similarity index 100% rename from C++/Advanced/32.cpp rename to C++/Hard/32.cpp diff --git a/C++/Advanced/33.cpp b/C++/Hard/33.cpp similarity index 100% rename from C++/Advanced/33.cpp rename to C++/Hard/33.cpp diff --git a/C++/Advanced/34.cpp b/C++/Hard/34.cpp similarity index 100% rename from C++/Advanced/34.cpp rename to C++/Hard/34.cpp diff --git a/C++/Advanced/35.cpp b/C++/Hard/35.cpp similarity index 100% rename from C++/Advanced/35.cpp rename to C++/Hard/35.cpp diff --git a/C++/Advanced/36.cpp b/C++/Hard/36.cpp similarity index 100% rename from C++/Advanced/36.cpp rename to C++/Hard/36.cpp diff --git a/C++/Advanced/37.cpp b/C++/Hard/37.cpp similarity index 100% rename from C++/Advanced/37.cpp rename to C++/Hard/37.cpp diff --git a/C++/Advanced/38.cpp b/C++/Hard/38.cpp similarity index 100% rename from C++/Advanced/38.cpp rename to C++/Hard/38.cpp diff --git a/C++/Advanced/39.cpp b/C++/Hard/39.cpp similarity index 100% rename from C++/Advanced/39.cpp rename to C++/Hard/39.cpp diff --git a/C++/Advanced/4.cpp b/C++/Hard/4.cpp similarity index 100% rename from C++/Advanced/4.cpp rename to C++/Hard/4.cpp diff --git a/C++/Advanced/40.cpp b/C++/Hard/40.cpp similarity index 100% rename from C++/Advanced/40.cpp rename to C++/Hard/40.cpp diff --git a/C++/Advanced/41.cpp b/C++/Hard/41.cpp similarity index 100% rename from C++/Advanced/41.cpp rename to C++/Hard/41.cpp diff --git a/C++/Advanced/42.cpp b/C++/Hard/42.cpp similarity index 100% rename from C++/Advanced/42.cpp rename to C++/Hard/42.cpp diff --git a/C++/Advanced/43.cpp b/C++/Hard/43.cpp similarity index 100% rename from C++/Advanced/43.cpp rename to C++/Hard/43.cpp diff --git a/C++/Advanced/44.cpp b/C++/Hard/44.cpp similarity index 100% rename from C++/Advanced/44.cpp rename to C++/Hard/44.cpp diff --git a/C++/Advanced/45.cpp b/C++/Hard/45.cpp similarity index 100% rename from C++/Advanced/45.cpp rename to C++/Hard/45.cpp diff --git a/C++/Advanced/46.cpp b/C++/Hard/46.cpp similarity index 100% rename from C++/Advanced/46.cpp rename to C++/Hard/46.cpp diff --git a/C++/Advanced/47.cpp b/C++/Hard/47.cpp similarity index 100% rename from C++/Advanced/47.cpp rename to C++/Hard/47.cpp diff --git a/C++/Advanced/48.cpp b/C++/Hard/48.cpp similarity index 100% rename from C++/Advanced/48.cpp rename to C++/Hard/48.cpp diff --git a/C++/Advanced/49.cpp b/C++/Hard/49.cpp similarity index 100% rename from C++/Advanced/49.cpp rename to C++/Hard/49.cpp diff --git a/C++/Advanced/5.cpp b/C++/Hard/5.cpp similarity index 100% rename from C++/Advanced/5.cpp rename to C++/Hard/5.cpp diff --git a/C++/Advanced/50.cpp b/C++/Hard/50.cpp similarity index 100% rename from C++/Advanced/50.cpp rename to C++/Hard/50.cpp diff --git a/C++/Advanced/6.cpp b/C++/Hard/6.cpp similarity index 100% rename from C++/Advanced/6.cpp rename to C++/Hard/6.cpp diff --git a/C++/Advanced/7.cpp b/C++/Hard/7.cpp similarity index 100% rename from C++/Advanced/7.cpp rename to C++/Hard/7.cpp diff --git a/C++/Advanced/8.cpp b/C++/Hard/8.cpp similarity index 100% rename from C++/Advanced/8.cpp rename to C++/Hard/8.cpp diff --git a/C++/Advanced/9.cpp b/C++/Hard/9.cpp similarity index 100% rename from C++/Advanced/9.cpp rename to C++/Hard/9.cpp diff --git a/C++/Intermediate/1.cpp b/C++/Medium/1.cpp similarity index 100% rename from C++/Intermediate/1.cpp rename to C++/Medium/1.cpp diff --git a/C++/Intermediate/10.cpp b/C++/Medium/10.cpp similarity index 100% rename from C++/Intermediate/10.cpp rename to C++/Medium/10.cpp diff --git a/C++/Intermediate/11.cpp b/C++/Medium/11.cpp similarity index 100% rename from C++/Intermediate/11.cpp rename to C++/Medium/11.cpp diff --git a/C++/Intermediate/12.cpp b/C++/Medium/12.cpp similarity index 100% rename from C++/Intermediate/12.cpp rename to C++/Medium/12.cpp diff --git a/C++/Intermediate/13.cpp b/C++/Medium/13.cpp similarity index 100% rename from C++/Intermediate/13.cpp rename to C++/Medium/13.cpp diff --git a/C++/Intermediate/14.cpp b/C++/Medium/14.cpp similarity index 100% rename from C++/Intermediate/14.cpp rename to C++/Medium/14.cpp diff --git a/C++/Intermediate/15.cpp b/C++/Medium/15.cpp similarity index 100% rename from C++/Intermediate/15.cpp rename to C++/Medium/15.cpp diff --git a/C++/Intermediate/16.cpp b/C++/Medium/16.cpp similarity index 100% rename from C++/Intermediate/16.cpp rename to C++/Medium/16.cpp diff --git a/C++/Intermediate/17.cpp b/C++/Medium/17.cpp similarity index 100% rename from C++/Intermediate/17.cpp rename to C++/Medium/17.cpp diff --git a/C++/Intermediate/18.cpp b/C++/Medium/18.cpp similarity index 100% rename from C++/Intermediate/18.cpp rename to C++/Medium/18.cpp diff --git a/C++/Intermediate/19.cpp b/C++/Medium/19.cpp similarity index 100% rename from C++/Intermediate/19.cpp rename to C++/Medium/19.cpp diff --git a/C++/Intermediate/2.cpp b/C++/Medium/2.cpp similarity index 100% rename from C++/Intermediate/2.cpp rename to C++/Medium/2.cpp diff --git a/C++/Intermediate/20.cpp b/C++/Medium/20.cpp similarity index 100% rename from C++/Intermediate/20.cpp rename to C++/Medium/20.cpp diff --git a/C++/Intermediate/21.cpp b/C++/Medium/21.cpp similarity index 100% rename from C++/Intermediate/21.cpp rename to C++/Medium/21.cpp diff --git a/C++/Intermediate/22.cpp b/C++/Medium/22.cpp similarity index 100% rename from C++/Intermediate/22.cpp rename to C++/Medium/22.cpp diff --git a/C++/Intermediate/23.cpp b/C++/Medium/23.cpp similarity index 100% rename from C++/Intermediate/23.cpp rename to C++/Medium/23.cpp diff --git a/C++/Intermediate/24.cpp b/C++/Medium/24.cpp similarity index 100% rename from C++/Intermediate/24.cpp rename to C++/Medium/24.cpp diff --git a/C++/Intermediate/25.cpp b/C++/Medium/25.cpp similarity index 100% rename from C++/Intermediate/25.cpp rename to C++/Medium/25.cpp diff --git a/C++/Intermediate/26.cpp b/C++/Medium/26.cpp similarity index 100% rename from C++/Intermediate/26.cpp rename to C++/Medium/26.cpp diff --git a/C++/Intermediate/27.cpp b/C++/Medium/27.cpp similarity index 100% rename from C++/Intermediate/27.cpp rename to C++/Medium/27.cpp diff --git a/C++/Intermediate/28.cpp b/C++/Medium/28.cpp similarity index 100% rename from C++/Intermediate/28.cpp rename to C++/Medium/28.cpp diff --git a/C++/Intermediate/29.cpp b/C++/Medium/29.cpp similarity index 100% rename from C++/Intermediate/29.cpp rename to C++/Medium/29.cpp diff --git a/C++/Intermediate/3.cpp b/C++/Medium/3.cpp similarity index 100% rename from C++/Intermediate/3.cpp rename to C++/Medium/3.cpp diff --git a/C++/Intermediate/30.cpp b/C++/Medium/30.cpp similarity index 100% rename from C++/Intermediate/30.cpp rename to C++/Medium/30.cpp diff --git a/C++/Intermediate/31.cpp b/C++/Medium/31.cpp similarity index 100% rename from C++/Intermediate/31.cpp rename to C++/Medium/31.cpp diff --git a/C++/Intermediate/32.cpp b/C++/Medium/32.cpp similarity index 100% rename from C++/Intermediate/32.cpp rename to C++/Medium/32.cpp diff --git a/C++/Intermediate/33.cpp b/C++/Medium/33.cpp similarity index 100% rename from C++/Intermediate/33.cpp rename to C++/Medium/33.cpp diff --git a/C++/Intermediate/34.cpp b/C++/Medium/34.cpp similarity index 100% rename from C++/Intermediate/34.cpp rename to C++/Medium/34.cpp diff --git a/C++/Intermediate/35.cpp b/C++/Medium/35.cpp similarity index 100% rename from C++/Intermediate/35.cpp rename to C++/Medium/35.cpp diff --git a/C++/Intermediate/36.cpp b/C++/Medium/36.cpp similarity index 100% rename from C++/Intermediate/36.cpp rename to C++/Medium/36.cpp diff --git a/C++/Intermediate/37.cpp b/C++/Medium/37.cpp similarity index 100% rename from C++/Intermediate/37.cpp rename to C++/Medium/37.cpp diff --git a/C++/Intermediate/38.cpp b/C++/Medium/38.cpp similarity index 100% rename from C++/Intermediate/38.cpp rename to C++/Medium/38.cpp diff --git a/C++/Intermediate/39.cpp b/C++/Medium/39.cpp similarity index 100% rename from C++/Intermediate/39.cpp rename to C++/Medium/39.cpp diff --git a/C++/Intermediate/4.cpp b/C++/Medium/4.cpp similarity index 100% rename from C++/Intermediate/4.cpp rename to C++/Medium/4.cpp diff --git a/C++/Intermediate/40.cpp b/C++/Medium/40.cpp similarity index 100% rename from C++/Intermediate/40.cpp rename to C++/Medium/40.cpp diff --git a/C++/Intermediate/41.cpp b/C++/Medium/41.cpp similarity index 100% rename from C++/Intermediate/41.cpp rename to C++/Medium/41.cpp diff --git a/C++/Intermediate/42.cpp b/C++/Medium/42.cpp similarity index 100% rename from C++/Intermediate/42.cpp rename to C++/Medium/42.cpp diff --git a/C++/Intermediate/43.cpp b/C++/Medium/43.cpp similarity index 100% rename from C++/Intermediate/43.cpp rename to C++/Medium/43.cpp diff --git a/C++/Intermediate/44.cpp b/C++/Medium/44.cpp similarity index 100% rename from C++/Intermediate/44.cpp rename to C++/Medium/44.cpp diff --git a/C++/Intermediate/45.cpp b/C++/Medium/45.cpp similarity index 100% rename from C++/Intermediate/45.cpp rename to C++/Medium/45.cpp diff --git a/C++/Intermediate/46.cpp b/C++/Medium/46.cpp similarity index 100% rename from C++/Intermediate/46.cpp rename to C++/Medium/46.cpp diff --git a/C++/Intermediate/47.cpp b/C++/Medium/47.cpp similarity index 100% rename from C++/Intermediate/47.cpp rename to C++/Medium/47.cpp diff --git a/C++/Intermediate/48.cpp b/C++/Medium/48.cpp similarity index 100% rename from C++/Intermediate/48.cpp rename to C++/Medium/48.cpp diff --git a/C++/Intermediate/49.cpp b/C++/Medium/49.cpp similarity index 100% rename from C++/Intermediate/49.cpp rename to C++/Medium/49.cpp diff --git a/C++/Intermediate/5.cpp b/C++/Medium/5.cpp similarity index 100% rename from C++/Intermediate/5.cpp rename to C++/Medium/5.cpp diff --git a/C++/Intermediate/50.cpp b/C++/Medium/50.cpp similarity index 100% rename from C++/Intermediate/50.cpp rename to C++/Medium/50.cpp diff --git a/C++/Intermediate/51.cpp b/C++/Medium/51.cpp similarity index 100% rename from C++/Intermediate/51.cpp rename to C++/Medium/51.cpp diff --git a/C++/Intermediate/52.cpp b/C++/Medium/52.cpp similarity index 100% rename from C++/Intermediate/52.cpp rename to C++/Medium/52.cpp diff --git a/C++/Intermediate/53.cpp b/C++/Medium/53.cpp similarity index 100% rename from C++/Intermediate/53.cpp rename to C++/Medium/53.cpp diff --git a/C++/Intermediate/54.cpp b/C++/Medium/54.cpp similarity index 100% rename from C++/Intermediate/54.cpp rename to C++/Medium/54.cpp diff --git a/C++/Intermediate/55.cpp b/C++/Medium/55.cpp similarity index 100% rename from C++/Intermediate/55.cpp rename to C++/Medium/55.cpp diff --git a/C++/Intermediate/56.cpp b/C++/Medium/56.cpp similarity index 100% rename from C++/Intermediate/56.cpp rename to C++/Medium/56.cpp diff --git a/C++/Intermediate/57.cpp b/C++/Medium/57.cpp similarity index 100% rename from C++/Intermediate/57.cpp rename to C++/Medium/57.cpp diff --git a/C++/Intermediate/58.cpp b/C++/Medium/58.cpp similarity index 100% rename from C++/Intermediate/58.cpp rename to C++/Medium/58.cpp diff --git a/C++/Intermediate/59.cpp b/C++/Medium/59.cpp similarity index 100% rename from C++/Intermediate/59.cpp rename to C++/Medium/59.cpp diff --git a/C++/Intermediate/6.cpp b/C++/Medium/6.cpp similarity index 100% rename from C++/Intermediate/6.cpp rename to C++/Medium/6.cpp diff --git a/C++/Intermediate/60.cpp b/C++/Medium/60.cpp similarity index 100% rename from C++/Intermediate/60.cpp rename to C++/Medium/60.cpp diff --git a/C++/Intermediate/61.cpp b/C++/Medium/61.cpp similarity index 100% rename from C++/Intermediate/61.cpp rename to C++/Medium/61.cpp diff --git a/C++/Intermediate/62.cpp b/C++/Medium/62.cpp similarity index 100% rename from C++/Intermediate/62.cpp rename to C++/Medium/62.cpp diff --git a/C++/Intermediate/63.cpp b/C++/Medium/63.cpp similarity index 100% rename from C++/Intermediate/63.cpp rename to C++/Medium/63.cpp diff --git a/C++/Intermediate/64.cpp b/C++/Medium/64.cpp similarity index 100% rename from C++/Intermediate/64.cpp rename to C++/Medium/64.cpp diff --git a/C++/Intermediate/65.cpp b/C++/Medium/65.cpp similarity index 100% rename from C++/Intermediate/65.cpp rename to C++/Medium/65.cpp diff --git a/C++/Intermediate/66.cpp b/C++/Medium/66.cpp similarity index 100% rename from C++/Intermediate/66.cpp rename to C++/Medium/66.cpp diff --git a/C++/Intermediate/7.cpp b/C++/Medium/7.cpp similarity index 100% rename from C++/Intermediate/7.cpp rename to C++/Medium/7.cpp diff --git a/C++/Intermediate/8.cpp b/C++/Medium/8.cpp similarity index 100% rename from C++/Intermediate/8.cpp rename to C++/Medium/8.cpp diff --git a/C++/Intermediate/9.cpp b/C++/Medium/9.cpp similarity index 100% rename from C++/Intermediate/9.cpp rename to C++/Medium/9.cpp From 0fc8b7d60d0f64ed759059671bc66adebda160fc Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:20:02 +0530 Subject: [PATCH 02/62] Create temp.txt --- Python/Easy/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python/Easy/temp.txt diff --git a/Python/Easy/temp.txt b/Python/Easy/temp.txt new file mode 100644 index 00000000..3d3bb244 --- /dev/null +++ b/Python/Easy/temp.txt @@ -0,0 +1 @@ +"." From a02d4edede0a8eddacb96c90f0bd60b9cb4d18fe Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:20:37 +0530 Subject: [PATCH 03/62] Create temp.txt --- Python/Medium/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python/Medium/temp.txt diff --git a/Python/Medium/temp.txt b/Python/Medium/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python/Medium/temp.txt @@ -0,0 +1 @@ + From 87bfa462a501c2759bde897f80f942a27a21aa41 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:21:25 +0530 Subject: [PATCH 04/62] Create temp.txt --- Python/Hard/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python/Hard/temp.txt diff --git a/Python/Hard/temp.txt b/Python/Hard/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python/Hard/temp.txt @@ -0,0 +1 @@ + From 9067a5b5746bb3715182542de76f680fdda860e1 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:24:07 +0530 Subject: [PATCH 05/62] Added easy python snippets --- Python/Easy/1.py | 9 +++++++++ Python/Easy/10.py | 4 ++++ Python/Easy/11.py | 9 +++++++++ Python/Easy/12.py | 10 ++++++++++ Python/Easy/13.py | 5 +++++ Python/Easy/14.py | 4 ++++ Python/Easy/15.py | 9 +++++++++ Python/Easy/16.py | 5 +++++ Python/Easy/17.py | 11 +++++++++++ Python/Easy/18.py | 4 ++++ Python/Easy/19.py | 5 +++++ Python/Easy/2.py | 5 +++++ Python/Easy/20.py | 5 +++++ Python/Easy/21.py | 2 ++ Python/Easy/22.py | 8 ++++++++ Python/Easy/23.py | 1 + Python/Easy/24.py | 1 + Python/Easy/25.py | 3 +++ Python/Easy/26.py | 1 + Python/Easy/27.py | 2 ++ Python/Easy/28.py | 3 +++ Python/Easy/29.py | 3 +++ Python/Easy/3.py | 10 ++++++++++ Python/Easy/30.py | 2 ++ Python/Easy/31.py | 2 ++ Python/Easy/32.py | 10 ++++++++++ Python/Easy/33.py | 3 +++ Python/Easy/34.py | 5 +++++ Python/Easy/35.py | 3 +++ Python/Easy/36.py | 3 +++ Python/Easy/37.py | 2 ++ Python/Easy/38.py | 2 ++ Python/Easy/39.py | 3 +++ Python/Easy/4.py | 9 +++++++++ Python/Easy/40.py | 3 +++ Python/Easy/41.py | 5 +++++ Python/Easy/42.py | 3 +++ Python/Easy/43.py | 2 ++ Python/Easy/44.py | 6 ++++++ Python/Easy/45.py | 5 +++++ Python/Easy/46.py | 4 ++++ Python/Easy/47.py | 1 + Python/Easy/48.py | 4 ++++ Python/Easy/49.py | 5 +++++ Python/Easy/5.py | 24 ++++++++++++++++++++++++ Python/Easy/50.py | 2 ++ Python/Easy/6.py | 13 +++++++++++++ Python/Easy/7.py | 19 +++++++++++++++++++ Python/Easy/8.py | 9 +++++++++ Python/Easy/9.py | 7 +++++++ 50 files changed, 275 insertions(+) create mode 100644 Python/Easy/1.py create mode 100644 Python/Easy/10.py create mode 100644 Python/Easy/11.py create mode 100644 Python/Easy/12.py create mode 100644 Python/Easy/13.py create mode 100644 Python/Easy/14.py create mode 100644 Python/Easy/15.py create mode 100644 Python/Easy/16.py create mode 100644 Python/Easy/17.py create mode 100644 Python/Easy/18.py create mode 100644 Python/Easy/19.py create mode 100644 Python/Easy/2.py create mode 100644 Python/Easy/20.py create mode 100644 Python/Easy/21.py create mode 100644 Python/Easy/22.py create mode 100644 Python/Easy/23.py create mode 100644 Python/Easy/24.py create mode 100644 Python/Easy/25.py create mode 100644 Python/Easy/26.py create mode 100644 Python/Easy/27.py create mode 100644 Python/Easy/28.py create mode 100644 Python/Easy/29.py create mode 100644 Python/Easy/3.py create mode 100644 Python/Easy/30.py create mode 100644 Python/Easy/31.py create mode 100644 Python/Easy/32.py create mode 100644 Python/Easy/33.py create mode 100644 Python/Easy/34.py create mode 100644 Python/Easy/35.py create mode 100644 Python/Easy/36.py create mode 100644 Python/Easy/37.py create mode 100644 Python/Easy/38.py create mode 100644 Python/Easy/39.py create mode 100644 Python/Easy/4.py create mode 100644 Python/Easy/40.py create mode 100644 Python/Easy/41.py create mode 100644 Python/Easy/42.py create mode 100644 Python/Easy/43.py create mode 100644 Python/Easy/44.py create mode 100644 Python/Easy/45.py create mode 100644 Python/Easy/46.py create mode 100644 Python/Easy/47.py create mode 100644 Python/Easy/48.py create mode 100644 Python/Easy/49.py create mode 100644 Python/Easy/5.py create mode 100644 Python/Easy/50.py create mode 100644 Python/Easy/6.py create mode 100644 Python/Easy/7.py create mode 100644 Python/Easy/8.py create mode 100644 Python/Easy/9.py diff --git a/Python/Easy/1.py b/Python/Easy/1.py new file mode 100644 index 00000000..d80b073d --- /dev/null +++ b/Python/Easy/1.py @@ -0,0 +1,9 @@ +If x==10 + print(x) +—------------------ + +if y > 5 + print(y) + +for i in range(5) + print(i) diff --git a/Python/Easy/10.py b/Python/Easy/10.py new file mode 100644 index 00000000..952701b3 --- /dev/null +++ b/Python/Easy/10.py @@ -0,0 +1,4 @@ +x = [1, 2, 3] +y = [1, 2, 3] +if x is y: + print("x and y are the same") diff --git a/Python/Easy/11.py b/Python/Easy/11.py new file mode 100644 index 00000000..d6de0cf7 --- /dev/null +++ b/Python/Easy/11.py @@ -0,0 +1,9 @@ +def outer(): + x = 10 + def inner(): + global x # Error: x is local to outer and cannot be made global + x = 5 + inner() + print(x) + +outer() diff --git a/Python/Easy/12.py b/Python/Easy/12.py new file mode 100644 index 00000000..c81e351c --- /dev/null +++ b/Python/Easy/12.py @@ -0,0 +1,10 @@ +class Animal: + def speak(self): + print("Animal speaks") + +class Dog(Animal): + def speak(self, sound): + print(sound) + +dog = Dog() +dog.speak() diff --git a/Python/Easy/13.py b/Python/Easy/13.py new file mode 100644 index 00000000..292911a3 --- /dev/null +++ b/Python/Easy/13.py @@ -0,0 +1,5 @@ +time = 5 +g = 9.8 +distance = g * t ** 2 # Error: 't' is not defined, typo in variable name +print("Distance traveled in free fall:", distance) + diff --git a/Python/Easy/14.py b/Python/Easy/14.py new file mode 100644 index 00000000..db2aeb59 --- /dev/null +++ b/Python/Easy/14.py @@ -0,0 +1,4 @@ +import maths +print(math.pow(2,3) +import randoms # Incorrect module name +print(random.randint(1, 10)) diff --git a/Python/Easy/15.py b/Python/Easy/15.py new file mode 100644 index 00000000..bcd02701 --- /dev/null +++ b/Python/Easy/15.py @@ -0,0 +1,9 @@ +Import +print(random.randint(1,10) + +Import random # Error: Incorrect case, 'import' should be lowercase +print(random.randint(1, 10)) + +import # Incomplete import statement +print(math.sqrt(25)) + diff --git a/Python/Easy/16.py b/Python/Easy/16.py new file mode 100644 index 00000000..603ce70e --- /dev/null +++ b/Python/Easy/16.py @@ -0,0 +1,5 @@ +L=(1,2,3,4) +L.append(5) +my_tuple = (1, 2, 3) + +my_tuple.append(4) # 'tuple' object has no 'append' method diff --git a/Python/Easy/17.py b/Python/Easy/17.py new file mode 100644 index 00000000..43ca75fc --- /dev/null +++ b/Python/Easy/17.py @@ -0,0 +1,11 @@ +a=int(input(‘enter a num’)) +b=int(input(‘enter another number’)) +Sum=a+b +print(‘Sum=’,sum) +a = int(input("Enter first number: ")) +b = int(input("Enter second number: ")) + +Sum = a + b +print("Sum: ", Sum) # Incorrect print syntax for variables + + diff --git a/Python/Easy/18.py b/Python/Easy/18.py new file mode 100644 index 00000000..a887bab5 --- /dev/null +++ b/Python/Easy/18.py @@ -0,0 +1,4 @@ +x = 5 +y = 10 +if x < 10 || y > 5: + print("x is less than 10 or y is greater than 5") diff --git a/Python/Easy/19.py b/Python/Easy/19.py new file mode 100644 index 00000000..b909533e --- /dev/null +++ b/Python/Easy/19.py @@ -0,0 +1,5 @@ +import math + +result = math.exp(1000) +print(result) + diff --git a/Python/Easy/2.py b/Python/Easy/2.py new file mode 100644 index 00000000..6798f893 --- /dev/null +++ b/Python/Easy/2.py @@ -0,0 +1,5 @@ +result = (5 + 3 * (2 + 4) + +value = (10 + 4 * (3 + 2 +calculation = ((6 * 4) + (7 * 2)) +print(calculation+value) diff --git a/Python/Easy/20.py b/Python/Easy/20.py new file mode 100644 index 00000000..c9ed0c2d --- /dev/null +++ b/Python/Easy/20.py @@ -0,0 +1,5 @@ +def print_elements(elements): + for element in elements: + print(element) + +print_elements(123) diff --git a/Python/Easy/21.py b/Python/Easy/21.py new file mode 100644 index 00000000..229915e5 --- /dev/null +++ b/Python/Easy/21.py @@ -0,0 +1,2 @@ +file_path = "C:\Users\Name\Documents\File.txt" + diff --git a/Python/Easy/22.py b/Python/Easy/22.py new file mode 100644 index 00000000..b4bcaa77 --- /dev/null +++ b/Python/Easy/22.py @@ -0,0 +1,8 @@ +import threading + +def thread_function(): + pass + +thread = threading.Thread(target=thread_function) +thread.start() +thread.start() \ No newline at end of file diff --git a/Python/Easy/23.py b/Python/Easy/23.py new file mode 100644 index 00000000..3691a206 --- /dev/null +++ b/Python/Easy/23.py @@ -0,0 +1 @@ +result = [1, 2, 3] + "string” diff --git a/Python/Easy/24.py b/Python/Easy/24.py new file mode 100644 index 00000000..395f5806 --- /dev/null +++ b/Python/Easy/24.py @@ -0,0 +1 @@ + func = lambda x: x+1; print(x) diff --git a/Python/Easy/25.py b/Python/Easy/25.py new file mode 100644 index 00000000..c2913bbf --- /dev/null +++ b/Python/Easy/25.py @@ -0,0 +1,3 @@ +def add(a, b): + return a + b + result = add(1, 2) + add diff --git a/Python/Easy/26.py b/Python/Easy/26.py new file mode 100644 index 00000000..c5bf4741 --- /dev/null +++ b/Python/Easy/26.py @@ -0,0 +1 @@ +my_dict = dict(1, 2) diff --git a/Python/Easy/27.py b/Python/Easy/27.py new file mode 100644 index 00000000..23a26a75 --- /dev/null +++ b/Python/Easy/27.py @@ -0,0 +1,2 @@ +data = [1, 'a', 3] + sorted(data) diff --git a/Python/Easy/28.py b/Python/Easy/28.py new file mode 100644 index 00000000..31549a63 --- /dev/null +++ b/Python/Easy/28.py @@ -0,0 +1,3 @@ + + len = 100 + print(len([1, 2, 3])) diff --git a/Python/Easy/29.py b/Python/Easy/29.py new file mode 100644 index 00000000..28be54b1 --- /dev/null +++ b/Python/Easy/29.py @@ -0,0 +1,3 @@ +my_dict = {'a': 1, 'b': 2} + for key in my_dict.keys(): + my_dict.pop(key) diff --git a/Python/Easy/3.py b/Python/Easy/3.py new file mode 100644 index 00000000..6c1b8692 --- /dev/null +++ b/Python/Easy/3.py @@ -0,0 +1,10 @@ +def greet() +print("Hello, world!") + +def add(a, b) +return a + b + +class Car +def __init__(self, make, model): +self.make = make +self.model = model diff --git a/Python/Easy/30.py b/Python/Easy/30.py new file mode 100644 index 00000000..098f08db --- /dev/null +++ b/Python/Easy/30.py @@ -0,0 +1,2 @@ + s = "abc" + s[0] = 'A' diff --git a/Python/Easy/31.py b/Python/Easy/31.py new file mode 100644 index 00000000..3e7400b7 --- /dev/null +++ b/Python/Easy/31.py @@ -0,0 +1,2 @@ + s = "3.14" + print(int(s)) diff --git a/Python/Easy/32.py b/Python/Easy/32.py new file mode 100644 index 00000000..1b9b5ba7 --- /dev/null +++ b/Python/Easy/32.py @@ -0,0 +1,10 @@ +my_list = [1, 2, 3, 4, +5, 6, 7 8, 9] +my_dict = { + 'key1': 1, + 'key2': 2, + 'key3': 3, + 'key4': 4 + 'key5': 5 +} + diff --git a/Python/Easy/33.py b/Python/Easy/33.py new file mode 100644 index 00000000..e1ddbd6d --- /dev/null +++ b/Python/Easy/33.py @@ -0,0 +1,3 @@ +pairs = [(1, 2), (3, 4)] + for x, y, z in pairs: + print(x, y, z) diff --git a/Python/Easy/34.py b/Python/Easy/34.py new file mode 100644 index 00000000..f4ca5227 --- /dev/null +++ b/Python/Easy/34.py @@ -0,0 +1,5 @@ +numbers = [1, 2, 3, 4] +for num in numbers + if num % 2 == 0: + print(f"{num} is even") + diff --git a/Python/Easy/35.py b/Python/Easy/35.py new file mode 100644 index 00000000..a4b1c8b5 --- /dev/null +++ b/Python/Easy/35.py @@ -0,0 +1,3 @@ +def multiply(a, b): + result = a * b +print(multiply(5, 3)) diff --git a/Python/Easy/36.py b/Python/Easy/36.py new file mode 100644 index 00000000..9a054362 --- /dev/null +++ b/Python/Easy/36.py @@ -0,0 +1,3 @@ +point = (5, 10, 15) +x, y = point +print(f"x: {x}, y: {y}") diff --git a/Python/Easy/37.py b/Python/Easy/37.py new file mode 100644 index 00000000..2bce4c98 --- /dev/null +++ b/Python/Easy/37.py @@ -0,0 +1,2 @@ +my_list = [1, 2, 3, 4, 5] +print(my_list[5:2]) \ No newline at end of file diff --git a/Python/Easy/38.py b/Python/Easy/38.py new file mode 100644 index 00000000..49543cbe --- /dev/null +++ b/Python/Easy/38.py @@ -0,0 +1,2 @@ +numbers = [1, 2, 3, 4, 5] +print(numbers[5]) diff --git a/Python/Easy/39.py b/Python/Easy/39.py new file mode 100644 index 00000000..bc60d97a --- /dev/null +++ b/Python/Easy/39.py @@ -0,0 +1,3 @@ +Modifying Immutable Objects +my_tuple = (1, 2, 3) +my_tuple[0] = 5 diff --git a/Python/Easy/4.py b/Python/Easy/4.py new file mode 100644 index 00000000..ab9606ee --- /dev/null +++ b/Python/Easy/4.py @@ -0,0 +1,9 @@ +message = ‘py" +print(message) + +title = "Python's "cool" feature" + +description = 'This is a Python "error example' + +sentence = “Hello, Python!” +print(sentence) diff --git a/Python/Easy/40.py b/Python/Easy/40.py new file mode 100644 index 00000000..e180d87f --- /dev/null +++ b/Python/Easy/40.py @@ -0,0 +1,3 @@ +text = """This is a multiline string +quote = 'This is an example of a + diff --git a/Python/Easy/41.py b/Python/Easy/41.py new file mode 100644 index 00000000..32e6ab54 --- /dev/null +++ b/Python/Easy/41.py @@ -0,0 +1,5 @@ +x = 10 +if x > 5: + print("x is greater than 5") +elif x > 8: + print("x is greater than 8") diff --git a/Python/Easy/42.py b/Python/Easy/42.py new file mode 100644 index 00000000..f68933f2 --- /dev/null +++ b/Python/Easy/42.py @@ -0,0 +1,3 @@ +x = 5 +if x == 3 and x == 5: + print("x is 3 or 5") diff --git a/Python/Easy/43.py b/Python/Easy/43.py new file mode 100644 index 00000000..8e9443e1 --- /dev/null +++ b/Python/Easy/43.py @@ -0,0 +1,2 @@ +coordinates = [10, 20] +coordinates[0] = 15 diff --git a/Python/Easy/44.py b/Python/Easy/44.py new file mode 100644 index 00000000..23602ed7 --- /dev/null +++ b/Python/Easy/44.py @@ -0,0 +1,6 @@ +x = 10 +if x > 5: + print("x is greater than 5") +elif x < 5: + print("x is less than 5") +else block. diff --git a/Python/Easy/45.py b/Python/Easy/45.py new file mode 100644 index 00000000..e8c842ab --- /dev/null +++ b/Python/Easy/45.py @@ -0,0 +1,5 @@ +def print_elements(x, y): + print(x, y) + +my_list = [1, 2, 3] +print_elements(*my_list) \ No newline at end of file diff --git a/Python/Easy/46.py b/Python/Easy/46.py new file mode 100644 index 00000000..441fe312 --- /dev/null +++ b/Python/Easy/46.py @@ -0,0 +1,4 @@ +def add(x, y): + return x + y + +add 5, 6 diff --git a/Python/Easy/47.py b/Python/Easy/47.py new file mode 100644 index 00000000..f8561c1b --- /dev/null +++ b/Python/Easy/47.py @@ -0,0 +1 @@ +my_dict = {1: "apple", [2]: "banana"} \ No newline at end of file diff --git a/Python/Easy/48.py b/Python/Easy/48.py new file mode 100644 index 00000000..6e9452e8 --- /dev/null +++ b/Python/Easy/48.py @@ -0,0 +1,4 @@ +def greet(): + return +result = greet() + "Hello" + diff --git a/Python/Easy/49.py b/Python/Easy/49.py new file mode 100644 index 00000000..c6524bd1 --- /dev/null +++ b/Python/Easy/49.py @@ -0,0 +1,5 @@ + for i in range(3): + if i == 1: + break +else: + print("Loop completed") diff --git a/Python/Easy/5.py b/Python/Easy/5.py new file mode 100644 index 00000000..eda45bf6 --- /dev/null +++ b/Python/Easy/5.py @@ -0,0 +1,24 @@ +prnt("Hello, world!") +for i in rang(5): + print(i) + + +pritn("Hello, world!") +for i in rnage(10): + print(i) +my_varaible = 10 +print(my_variable) + +x = 10 +y = 5 +result = x - y + z +if x = 5: + print("x is 5") + +if x > 10: + print("x is greater") +else if x == 10: + print("x is equal") + +del my_function() + diff --git a/Python/Easy/50.py b/Python/Easy/50.py new file mode 100644 index 00000000..7df7764c --- /dev/null +++ b/Python/Easy/50.py @@ -0,0 +1,2 @@ + if 5 > "3": + print("5 is greater") diff --git a/Python/Easy/6.py b/Python/Easy/6.py new file mode 100644 index 00000000..4e8ca90c --- /dev/null +++ b/Python/Easy/6.py @@ -0,0 +1,13 @@ +funtion greet(): + print("Hello") +def greet: + print("Hello") + +def funtion greet(): + print("Hello") + +def greet: + print("Hello") + +def greet(): + print("Hello") diff --git a/Python/Easy/7.py b/Python/Easy/7.py new file mode 100644 index 00000000..4f42bfab --- /dev/null +++ b/Python/Easy/7.py @@ -0,0 +1,19 @@ +None = "some_value" +if None == "some_value": + print("This shouldn't work, None is a keyword!") +True = 1 +if True: + print("This will cause an error because 'True' is a reserved keyword.") + +def for(x): + return x * 2 + +result = for(5) +print(result) + +if return > 5: + print("You can't use 'return' as a variable name!") + +class = "AdvancedPython" +print("This won't work because 'class' is a reserved keyword in Python.") + diff --git a/Python/Easy/8.py b/Python/Easy/8.py new file mode 100644 index 00000000..4a2db9e2 --- /dev/null +++ b/Python/Easy/8.py @@ -0,0 +1,9 @@ +if x = 5: + print("x is 5") +if x == 5: + x = 10 + print("x is now 10") + +x = 5 +if x = 5: + print("x is 5") diff --git a/Python/Easy/9.py b/Python/Easy/9.py new file mode 100644 index 00000000..f8779947 --- /dev/null +++ b/Python/Easy/9.py @@ -0,0 +1,7 @@ +add = lambda x, y: x + y +print(add(3, 5)) +add = lambda x, y: print(x + y) +add(3, 5) + +add = lambda x, y, : x + y +print(add(3, 5)) From 0b2c9e3e39c783ff7a0a6be02b1e8ee099e2d8dd Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:26:15 +0530 Subject: [PATCH 06/62] added medium level snippets --- Python/Hard/10.py | 3 +++ Python/Hard/101.py | 5 +++++ Python/Hard/103.py | 4 ++++ Python/Hard/106.py | 2 ++ Python/Hard/107.py | 19 +++++++++++++++++++ Python/Hard/11.py | 4 ++++ Python/Hard/110.py | 3 +++ Python/Hard/114.py | 3 +++ Python/Hard/118.py | 4 ++++ Python/Hard/12.py | 3 +++ Python/Hard/121.py | 18 ++++++++++++++++++ Python/Hard/124.py | 31 +++++++++++++++++++++++++++++++ Python/Hard/130.py | 8 ++++++++ Python/Hard/132.py | 2 ++ Python/Hard/133.py | 21 +++++++++++++++++++++ Python/Hard/136.py | 2 ++ Python/Hard/142.py | 3 +++ Python/Hard/143.py | 5 +++++ Python/Hard/144.py | 4 ++++ Python/Hard/147.py | 2 ++ Python/Hard/148.py | 4 ++++ Python/Hard/150.py | 18 ++++++++++++++++++ Python/Hard/17.py | 2 ++ Python/Hard/18.py | 3 +++ Python/Hard/2.py | 2 ++ Python/Hard/22.py | 8 ++++++++ Python/Hard/23.py | 8 ++++++++ Python/Hard/26.py | 10 ++++++++++ Python/Hard/27.py | 9 +++++++++ Python/Hard/29.py | 5 +++++ Python/Hard/3.py | 3 +++ Python/Hard/32.py | 7 +++++++ Python/Hard/33.py | 7 +++++++ Python/Hard/37.py | 4 ++++ Python/Hard/40.py | 2 ++ Python/Hard/41.py | 4 ++++ Python/Hard/42.py | 1 + Python/Hard/44.py | 14 ++++++++++++++ Python/Hard/48.py | 7 +++++++ Python/Hard/50.py | 21 +++++++++++++++++++++ Python/Hard/52.py | 7 +++++++ Python/Hard/55.py | 3 +++ Python/Hard/61.py | 12 ++++++++++++ Python/Hard/65.py | 23 +++++++++++++++++++++++ Python/Hard/69.py | 28 ++++++++++++++++++++++++++++ Python/Hard/73.py | 3 +++ Python/Hard/75.py | 4 ++++ Python/Hard/76.py | 16 ++++++++++++++++ Python/Hard/79.py | 19 +++++++++++++++++++ Python/Hard/81.py | 24 ++++++++++++++++++++++++ Python/Hard/93.py | 3 +++ Python/Hard/96.py | 10 ++++++++++ Python/Hard/98.py | 5 +++++ Python/Hard/99.py | 2 ++ 54 files changed, 444 insertions(+) create mode 100644 Python/Hard/10.py create mode 100644 Python/Hard/101.py create mode 100644 Python/Hard/103.py create mode 100644 Python/Hard/106.py create mode 100644 Python/Hard/107.py create mode 100644 Python/Hard/11.py create mode 100644 Python/Hard/110.py create mode 100644 Python/Hard/114.py create mode 100644 Python/Hard/118.py create mode 100644 Python/Hard/12.py create mode 100644 Python/Hard/121.py create mode 100644 Python/Hard/124.py create mode 100644 Python/Hard/130.py create mode 100644 Python/Hard/132.py create mode 100644 Python/Hard/133.py create mode 100644 Python/Hard/136.py create mode 100644 Python/Hard/142.py create mode 100644 Python/Hard/143.py create mode 100644 Python/Hard/144.py create mode 100644 Python/Hard/147.py create mode 100644 Python/Hard/148.py create mode 100644 Python/Hard/150.py create mode 100644 Python/Hard/17.py create mode 100644 Python/Hard/18.py create mode 100644 Python/Hard/2.py create mode 100644 Python/Hard/22.py create mode 100644 Python/Hard/23.py create mode 100644 Python/Hard/26.py create mode 100644 Python/Hard/27.py create mode 100644 Python/Hard/29.py create mode 100644 Python/Hard/3.py create mode 100644 Python/Hard/32.py create mode 100644 Python/Hard/33.py create mode 100644 Python/Hard/37.py create mode 100644 Python/Hard/40.py create mode 100644 Python/Hard/41.py create mode 100644 Python/Hard/42.py create mode 100644 Python/Hard/44.py create mode 100644 Python/Hard/48.py create mode 100644 Python/Hard/50.py create mode 100644 Python/Hard/52.py create mode 100644 Python/Hard/55.py create mode 100644 Python/Hard/61.py create mode 100644 Python/Hard/65.py create mode 100644 Python/Hard/69.py create mode 100644 Python/Hard/73.py create mode 100644 Python/Hard/75.py create mode 100644 Python/Hard/76.py create mode 100644 Python/Hard/79.py create mode 100644 Python/Hard/81.py create mode 100644 Python/Hard/93.py create mode 100644 Python/Hard/96.py create mode 100644 Python/Hard/98.py create mode 100644 Python/Hard/99.py diff --git a/Python/Hard/10.py b/Python/Hard/10.py new file mode 100644 index 00000000..08763d2a --- /dev/null +++ b/Python/Hard/10.py @@ -0,0 +1,3 @@ +numbers = [1, 2, 3, 4, 5] +squared = [x** for x in numbers] +print(squared) diff --git a/Python/Hard/101.py b/Python/Hard/101.py new file mode 100644 index 00000000..e549a10c --- /dev/null +++ b/Python/Hard/101.py @@ -0,0 +1,5 @@ +if 5 < x < y > z: + print("Puzzling condition") + +if a == b != c > d < e: + print("Confusing multiple conditions") diff --git a/Python/Hard/103.py b/Python/Hard/103.py new file mode 100644 index 00000000..d6f802a4 --- /dev/null +++ b/Python/Hard/103.py @@ -0,0 +1,4 @@ +def my_function(x, y): + print(x + y) + +my_function(x = 5, 3) diff --git a/Python/Hard/106.py b/Python/Hard/106.py new file mode 100644 index 00000000..118f2178 --- /dev/null +++ b/Python/Hard/106.py @@ -0,0 +1,2 @@ +a = 5, b = 10, c = 15 +print(a, b, c) diff --git a/Python/Hard/107.py b/Python/Hard/107.py new file mode 100644 index 00000000..a660e01b --- /dev/null +++ b/Python/Hard/107.py @@ -0,0 +1,19 @@ +def check_numbers(numbers): + for num in numbers: + if num % 2 == 0: + print(f"{num} is even") + return num * 2 + else: + return num * 3 + print(f"{num} is odd") + +result = check_numbers([1, 2, 3, 4]) +print(result) + +def find_number(numbers): + for i in numbers: + if i == 5: + return i * 2 + else: + print(i) + return i + 3 diff --git a/Python/Hard/11.py b/Python/Hard/11.py new file mode 100644 index 00000000..4a754e82 --- /dev/null +++ b/Python/Hard/11.py @@ -0,0 +1,4 @@ +try + result = 10 / 0 +except (ZeroDivisionError) + print("Error occurred") diff --git a/Python/Hard/110.py b/Python/Hard/110.py new file mode 100644 index 00000000..c4a8c872 --- /dev/null +++ b/Python/Hard/110.py @@ -0,0 +1,3 @@ +def add(a, b): + return a + b + result = add(1, 2) + add diff --git a/Python/Hard/114.py b/Python/Hard/114.py new file mode 100644 index 00000000..2ead61f0 --- /dev/null +++ b/Python/Hard/114.py @@ -0,0 +1,3 @@ + s = "hello world" + result = s.split(" ") + Result = s.split("") diff --git a/Python/Hard/118.py b/Python/Hard/118.py new file mode 100644 index 00000000..9bcad4bf --- /dev/null +++ b/Python/Hard/118.py @@ -0,0 +1,4 @@ +name = "John" +lastname = "Wick" +age = 25 +print("Name: " + name + lastname ", Age: " + age "") diff --git a/Python/Hard/12.py b/Python/Hard/12.py new file mode 100644 index 00000000..094483e1 --- /dev/null +++ b/Python/Hard/12.py @@ -0,0 +1,3 @@ +def greet(*args, **kwargs): + print("Hello, " + args + " " + kwargs) +greet("John", last_name="Doe") diff --git a/Python/Hard/121.py b/Python/Hard/121.py new file mode 100644 index 00000000..bf47758d --- /dev/null +++ b/Python/Hard/121.py @@ -0,0 +1,18 @@ +message = ‘py" +print(message) + +title = "Python's "cool" feature" + +description = 'This is a Python "error example' + +sentence = “Hello, Python!” + + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) \ No newline at end of file diff --git a/Python/Hard/124.py b/Python/Hard/124.py new file mode 100644 index 00000000..5feff332 --- /dev/null +++ b/Python/Hard/124.py @@ -0,0 +1,31 @@ +None = "some_value" +if None == "some_value": + print("This shouldn't work, None is a keyword!") + +True = 1 +if True: + print("This will cause an error because 'True' is a reserved keyword.") + +def for(x): + return x * 2 + +result = for(5) +print(result) + +return = 10 +if return > 5: + print("You can't use 'return' as a variable name!") + + +class = "AdvancedPython" +print("This won't work because 'class' is a reserved keyword in Python.") + + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) diff --git a/Python/Hard/130.py b/Python/Hard/130.py new file mode 100644 index 00000000..8da31ae0 --- /dev/null +++ b/Python/Hard/130.py @@ -0,0 +1,8 @@ +def add_numbers(a, b) + result = a + b + +num1 = 5 +num2 = 10 + +print(add_numbers(num1, num2)) + diff --git a/Python/Hard/132.py b/Python/Hard/132.py new file mode 100644 index 00000000..51f69870 --- /dev/null +++ b/Python/Hard/132.py @@ -0,0 +1,2 @@ +Import numpy: +print(math.trunc(5.677) \ No newline at end of file diff --git a/Python/Hard/133.py b/Python/Hard/133.py new file mode 100644 index 00000000..4f2d90b5 --- /dev/null +++ b/Python/Hard/133.py @@ -0,0 +1,21 @@ +class Shape: + def area(self): + return "Calculating area..." + +class Circle(Shape): + + def area(self, radius): + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) +shape = Shape() +circle = Circle() + +print(shape.area()) +print(circle.area()) diff --git a/Python/Hard/136.py b/Python/Hard/136.py new file mode 100644 index 00000000..794b01e9 --- /dev/null +++ b/Python/Hard/136.py @@ -0,0 +1,2 @@ +numbers = [1, 2, 3, 4, 5] +print(numbers[5]) diff --git a/Python/Hard/142.py b/Python/Hard/142.py new file mode 100644 index 00000000..64aeff8c --- /dev/null +++ b/Python/Hard/142.py @@ -0,0 +1,3 @@ +def add(a, b): +sum = a + b + return sum diff --git a/Python/Hard/143.py b/Python/Hard/143.py new file mode 100644 index 00000000..419fab52 --- /dev/null +++ b/Python/Hard/143.py @@ -0,0 +1,5 @@ +x = 5 +if x < 10: + print("x is less than 10") +else x > 10: + print("x is greater than 10") diff --git a/Python/Hard/144.py b/Python/Hard/144.py new file mode 100644 index 00000000..e66e91d3 --- /dev/null +++ b/Python/Hard/144.py @@ -0,0 +1,4 @@ +counter = 0 +while counter = 5: + print(counter) + counter += 1 diff --git a/Python/Hard/147.py b/Python/Hard/147.py new file mode 100644 index 00000000..eb76aaf9 --- /dev/null +++ b/Python/Hard/147.py @@ -0,0 +1,2 @@ +x = 10 +return x diff --git a/Python/Hard/148.py b/Python/Hard/148.py new file mode 100644 index 00000000..76ae0477 --- /dev/null +++ b/Python/Hard/148.py @@ -0,0 +1,4 @@ +try: + print(1 / 0) +except ZeroDivisionError + print("Can't divide by zero") diff --git a/Python/Hard/150.py b/Python/Hard/150.py new file mode 100644 index 00000000..b62480c7 --- /dev/null +++ b/Python/Hard/150.py @@ -0,0 +1,18 @@ +class Dog: + def __init__(name): + self.name = name + + def bark(): + print(self.name + " is barking") + +my_dog = Dog("Buddy") +my_dog.bark() +def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) diff --git a/Python/Hard/17.py b/Python/Hard/17.py new file mode 100644 index 00000000..4a694033 --- /dev/null +++ b/Python/Hard/17.py @@ -0,0 +1,2 @@ +Import math: +print(math.trunc(5.677) diff --git a/Python/Hard/18.py b/Python/Hard/18.py new file mode 100644 index 00000000..824a011d --- /dev/null +++ b/Python/Hard/18.py @@ -0,0 +1,3 @@ +for i in range(5) +break +print(i) diff --git a/Python/Hard/2.py b/Python/Hard/2.py new file mode 100644 index 00000000..96f22e93 --- /dev/null +++ b/Python/Hard/2.py @@ -0,0 +1,2 @@ +x = 10 +print(len(x)) diff --git a/Python/Hard/22.py b/Python/Hard/22.py new file mode 100644 index 00000000..08b50a84 --- /dev/null +++ b/Python/Hard/22.py @@ -0,0 +1,8 @@ +a=3 +b=4 +print(a+b+c) + +x = 5 +y = z + +print(x + y) diff --git a/Python/Hard/23.py b/Python/Hard/23.py new file mode 100644 index 00000000..3be4031f --- /dev/null +++ b/Python/Hard/23.py @@ -0,0 +1,8 @@ +n=12 +If n%2=0: + print(‘even number’) + +num = 15 + +if num = 10: + print("Number is 10") diff --git a/Python/Hard/26.py b/Python/Hard/26.py new file mode 100644 index 00000000..89f4bcd7 --- /dev/null +++ b/Python/Hard/26.py @@ -0,0 +1,10 @@ +def multiply: + Return a*b +a=int(input(‘enter a num’)) +b=int(input(‘enter another number’)) + +def square(num): + return num * num + + +square diff --git a/Python/Hard/27.py b/Python/Hard/27.py new file mode 100644 index 00000000..bf3b6b58 --- /dev/null +++ b/Python/Hard/27.py @@ -0,0 +1,9 @@ +age = 25 +message = "I am " + age + " years old." +print(message) + +age = "25" + +message = "I am " + age + " years old." + +print(message) diff --git a/Python/Hard/29.py b/Python/Hard/29.py new file mode 100644 index 00000000..2724d901 --- /dev/null +++ b/Python/Hard/29.py @@ -0,0 +1,5 @@ +def infinite_recursion(n): + return infinite_recursion(n + 1) + +result = infinite_recursion(0) +print(result) diff --git a/Python/Hard/3.py b/Python/Hard/3.py new file mode 100644 index 00000000..2b6e9d84 --- /dev/null +++ b/Python/Hard/3.py @@ -0,0 +1,3 @@ +name = "John" +age = 25 +print("Name: " + name + ", Age: " + age) diff --git a/Python/Hard/32.py b/Python/Hard/32.py new file mode 100644 index 00000000..08a5f6b8 --- /dev/null +++ b/Python/Hard/32.py @@ -0,0 +1,7 @@ +import sys + +sys.setrecursionlimit(10) +def recursive_function(): + recursive_function() + +recursive_function() diff --git a/Python/Hard/33.py b/Python/Hard/33.py new file mode 100644 index 00000000..08a5f6b8 --- /dev/null +++ b/Python/Hard/33.py @@ -0,0 +1,7 @@ +import sys + +sys.setrecursionlimit(10) +def recursive_function(): + recursive_function() + +recursive_function() diff --git a/Python/Hard/37.py b/Python/Hard/37.py new file mode 100644 index 00000000..5ffb9a4f --- /dev/null +++ b/Python/Hard/37.py @@ -0,0 +1,4 @@ +def add(a, b): + return a + b + result = add(1, 2) + add + diff --git a/Python/Hard/40.py b/Python/Hard/40.py new file mode 100644 index 00000000..561415e8 --- /dev/null +++ b/Python/Hard/40.py @@ -0,0 +1,2 @@ +my_dict = {'a': 1, 'b': 2} +print(my_dict['c']) diff --git a/Python/Hard/41.py b/Python/Hard/41.py new file mode 100644 index 00000000..7f8a37cf --- /dev/null +++ b/Python/Hard/41.py @@ -0,0 +1,4 @@ +s = "hello world" +result = s.split(" ") +Result = s.split("") + diff --git a/Python/Hard/42.py b/Python/Hard/42.py new file mode 100644 index 00000000..fc1bdacb --- /dev/null +++ b/Python/Hard/42.py @@ -0,0 +1 @@ +r = range(3, 10, 0) diff --git a/Python/Hard/44.py b/Python/Hard/44.py new file mode 100644 index 00000000..356df61a --- /dev/null +++ b/Python/Hard/44.py @@ -0,0 +1,14 @@ +def calculate_sum(): + sum = 0 + + + numbers = [1, 2, 3, 4] + total = sum(numbers) + print("The sum of the numbers is:", total) + + + more_numbers = [10, 20, 30] + result = sum(more_numbers) + print("The result is:", result) + +calculate_sum() diff --git a/Python/Hard/48.py b/Python/Hard/48.py new file mode 100644 index 00000000..d8cf07f6 --- /dev/null +++ b/Python/Hard/48.py @@ -0,0 +1,7 @@ +class A: + def method(): + print("Hello") + +a = A() +a.method() + diff --git a/Python/Hard/50.py b/Python/Hard/50.py new file mode 100644 index 00000000..d8340cfa --- /dev/null +++ b/Python/Hard/50.py @@ -0,0 +1,21 @@ +def increment_example(): + x = 10 + + + y = x++ + + + print("The value of y is:", y) + + + print("The value of x after incrementing is:", x) + +increment_example() + + +a = 7 +b = a++ + + +print("The value of b is:", b) +print("The value of a after incrementing is:", a) diff --git a/Python/Hard/52.py b/Python/Hard/52.py new file mode 100644 index 00000000..06de13ee --- /dev/null +++ b/Python/Hard/52.py @@ -0,0 +1,7 @@ +x = 15 +if x > 10: + print("x is greater than 10") +else: + print("x is less than or equal to 10") +elif x == 15: + print("x is equal to 15") diff --git a/Python/Hard/55.py b/Python/Hard/55.py new file mode 100644 index 00000000..8a876ea9 --- /dev/null +++ b/Python/Hard/55.py @@ -0,0 +1,3 @@ +try: + value = int("abc") +print("This won't execute") diff --git a/Python/Hard/61.py b/Python/Hard/61.py new file mode 100644 index 00000000..961eeca6 --- /dev/null +++ b/Python/Hard/61.py @@ -0,0 +1,12 @@ +def print_numbers(): + + for i in range[1, 6]: + + print i) + + i += 1 + + print("Final value of i:", i) + + +print_numbers() diff --git a/Python/Hard/65.py b/Python/Hard/65.py new file mode 100644 index 00000000..95e63917 --- /dev/null +++ b/Python/Hard/65.py @@ -0,0 +1,23 @@ + +def check_numbers(): + + for i in range("5"): + + + print i + + + if i = "5": + + print("Finally reached five, which shouldn't be possible!") + + + break i + + j + 1 + + + print("Loop ended at:", i) + + +check_numbers() diff --git a/Python/Hard/69.py b/Python/Hard/69.py new file mode 100644 index 00000000..b1b73360 --- /dev/null +++ b/Python/Hard/69.py @@ -0,0 +1,28 @@ +x = 10 +y = "5" + + +if x > 5: + if y > 3: + print("y is greater than 3") + elif x == 10: + print("x is exactly 10") + else: + print("This won't be printed, but it's here anyway") + +elif x < 5: + print("x is less than 5") + + +else: + print("x is exactly 5") + + +if x == "10": + print("x is string 10") + +if y == 5: + print("y is integer 5") + +else: + print("No match for y") diff --git a/Python/Hard/73.py b/Python/Hard/73.py new file mode 100644 index 00000000..f13cd1f8 --- /dev/null +++ b/Python/Hard/73.py @@ -0,0 +1,3 @@ +list1 = [1, 2, 3] +list2 = [4, 5, 6] +list1 += list2() diff --git a/Python/Hard/75.py b/Python/Hard/75.py new file mode 100644 index 00000000..fd719455 --- /dev/null +++ b/Python/Hard/75.py @@ -0,0 +1,4 @@ +try: + result = 10 / 0 +finally: + print("This is printed after the exception") diff --git a/Python/Hard/76.py b/Python/Hard/76.py new file mode 100644 index 00000000..7f99ef07 --- /dev/null +++ b/Python/Hard/76.py @@ -0,0 +1,16 @@ + +x = 10 + 2 * 3 ** 2 + + +y = 5 + 3 ** 2 * 2 - (4 / 2) + 1 + + +x = "Value: " + str(x) + + +z = x + 10 * 2 + + +print("Final value of x:", x) +print("Value of y:", y) +print("Value of z:", z) \ No newline at end of file diff --git a/Python/Hard/79.py b/Python/Hard/79.py new file mode 100644 index 00000000..eed734dc --- /dev/null +++ b/Python/Hard/79.py @@ -0,0 +1,19 @@ +def multiply(a, b): + return a * b + + +result = multiply(2, 3) + multiply(2, '4') + + +print(result + undefined_variable) + + +if multiply(5, 0) = 0: + print("This won't print due to syntax error") + + +for i in range(5) + print("Loop iteration:", i) + + +print("Final result is:", result, "with multiplication check:", multiply(4, 'five')) diff --git a/Python/Hard/81.py b/Python/Hard/81.py new file mode 100644 index 00000000..5b88cf1c --- /dev/null +++ b/Python/Hard/81.py @@ -0,0 +1,24 @@ +def outer(): + def inner(): + print(x) + inner() + + +x = "5" + + +def another_function(): + print("This is another function.") + inner() + +outer() + + +def yet_another_function(): + global x + x = x + 1 + +yet_another_function() + + +print("Final value of x is: " + x) diff --git a/Python/Hard/93.py b/Python/Hard/93.py new file mode 100644 index 00000000..ac22c448 --- /dev/null +++ b/Python/Hard/93.py @@ -0,0 +1,3 @@ +x = 10 +y = 10 +if x is y: print("Same") diff --git a/Python/Hard/96.py b/Python/Hard/96.py new file mode 100644 index 00000000..76e8ff0e --- /dev/null +++ b/Python/Hard/96.py @@ -0,0 +1,10 @@ +my_list = [1, 2, 3, 4, +5, 6, 7 8, 9] + +my_dict = { + 'key1': 1, + 'key2': 2, + 'key3': 3, + 'key4': 4 + 'key5': 5 +} diff --git a/Python/Hard/98.py b/Python/Hard/98.py new file mode 100644 index 00000000..2a6c4a08 --- /dev/null +++ b/Python/Hard/98.py @@ -0,0 +1,5 @@ +x = 10 +else: + print("x is something else") +x = 5 +continue diff --git a/Python/Hard/99.py b/Python/Hard/99.py new file mode 100644 index 00000000..ca7f87a9 --- /dev/null +++ b/Python/Hard/99.py @@ -0,0 +1,2 @@ +squared = [x**2 for x in range(10) if x > 2 print(x)] +evens = [x for x in range(20) if x % 2 == 0 print(x)] From 2e8a487825f936b045d8c95d6efa3b1a2f6ffa27 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:27:02 +0530 Subject: [PATCH 07/62] Delete Python/Hard directory --- Python/Hard/10.py | 3 --- Python/Hard/101.py | 5 ----- Python/Hard/103.py | 4 ---- Python/Hard/106.py | 2 -- Python/Hard/107.py | 19 ------------------- Python/Hard/11.py | 4 ---- Python/Hard/110.py | 3 --- Python/Hard/114.py | 3 --- Python/Hard/118.py | 4 ---- Python/Hard/12.py | 3 --- Python/Hard/121.py | 18 ------------------ Python/Hard/124.py | 31 ------------------------------- Python/Hard/130.py | 8 -------- Python/Hard/132.py | 2 -- Python/Hard/133.py | 21 --------------------- Python/Hard/136.py | 2 -- Python/Hard/142.py | 3 --- Python/Hard/143.py | 5 ----- Python/Hard/144.py | 4 ---- Python/Hard/147.py | 2 -- Python/Hard/148.py | 4 ---- Python/Hard/150.py | 18 ------------------ Python/Hard/17.py | 2 -- Python/Hard/18.py | 3 --- Python/Hard/2.py | 2 -- Python/Hard/22.py | 8 -------- Python/Hard/23.py | 8 -------- Python/Hard/26.py | 10 ---------- Python/Hard/27.py | 9 --------- Python/Hard/29.py | 5 ----- Python/Hard/3.py | 3 --- Python/Hard/32.py | 7 ------- Python/Hard/33.py | 7 ------- Python/Hard/37.py | 4 ---- Python/Hard/40.py | 2 -- Python/Hard/41.py | 4 ---- Python/Hard/42.py | 1 - Python/Hard/44.py | 14 -------------- Python/Hard/48.py | 7 ------- Python/Hard/50.py | 21 --------------------- Python/Hard/52.py | 7 ------- Python/Hard/55.py | 3 --- Python/Hard/61.py | 12 ------------ Python/Hard/65.py | 23 ----------------------- Python/Hard/69.py | 28 ---------------------------- Python/Hard/73.py | 3 --- Python/Hard/75.py | 4 ---- Python/Hard/76.py | 16 ---------------- Python/Hard/79.py | 19 ------------------- Python/Hard/81.py | 24 ------------------------ Python/Hard/93.py | 3 --- Python/Hard/96.py | 10 ---------- Python/Hard/98.py | 5 ----- Python/Hard/99.py | 2 -- Python/Hard/temp.txt | 1 - 55 files changed, 445 deletions(-) delete mode 100644 Python/Hard/10.py delete mode 100644 Python/Hard/101.py delete mode 100644 Python/Hard/103.py delete mode 100644 Python/Hard/106.py delete mode 100644 Python/Hard/107.py delete mode 100644 Python/Hard/11.py delete mode 100644 Python/Hard/110.py delete mode 100644 Python/Hard/114.py delete mode 100644 Python/Hard/118.py delete mode 100644 Python/Hard/12.py delete mode 100644 Python/Hard/121.py delete mode 100644 Python/Hard/124.py delete mode 100644 Python/Hard/130.py delete mode 100644 Python/Hard/132.py delete mode 100644 Python/Hard/133.py delete mode 100644 Python/Hard/136.py delete mode 100644 Python/Hard/142.py delete mode 100644 Python/Hard/143.py delete mode 100644 Python/Hard/144.py delete mode 100644 Python/Hard/147.py delete mode 100644 Python/Hard/148.py delete mode 100644 Python/Hard/150.py delete mode 100644 Python/Hard/17.py delete mode 100644 Python/Hard/18.py delete mode 100644 Python/Hard/2.py delete mode 100644 Python/Hard/22.py delete mode 100644 Python/Hard/23.py delete mode 100644 Python/Hard/26.py delete mode 100644 Python/Hard/27.py delete mode 100644 Python/Hard/29.py delete mode 100644 Python/Hard/3.py delete mode 100644 Python/Hard/32.py delete mode 100644 Python/Hard/33.py delete mode 100644 Python/Hard/37.py delete mode 100644 Python/Hard/40.py delete mode 100644 Python/Hard/41.py delete mode 100644 Python/Hard/42.py delete mode 100644 Python/Hard/44.py delete mode 100644 Python/Hard/48.py delete mode 100644 Python/Hard/50.py delete mode 100644 Python/Hard/52.py delete mode 100644 Python/Hard/55.py delete mode 100644 Python/Hard/61.py delete mode 100644 Python/Hard/65.py delete mode 100644 Python/Hard/69.py delete mode 100644 Python/Hard/73.py delete mode 100644 Python/Hard/75.py delete mode 100644 Python/Hard/76.py delete mode 100644 Python/Hard/79.py delete mode 100644 Python/Hard/81.py delete mode 100644 Python/Hard/93.py delete mode 100644 Python/Hard/96.py delete mode 100644 Python/Hard/98.py delete mode 100644 Python/Hard/99.py delete mode 100644 Python/Hard/temp.txt diff --git a/Python/Hard/10.py b/Python/Hard/10.py deleted file mode 100644 index 08763d2a..00000000 --- a/Python/Hard/10.py +++ /dev/null @@ -1,3 +0,0 @@ -numbers = [1, 2, 3, 4, 5] -squared = [x** for x in numbers] -print(squared) diff --git a/Python/Hard/101.py b/Python/Hard/101.py deleted file mode 100644 index e549a10c..00000000 --- a/Python/Hard/101.py +++ /dev/null @@ -1,5 +0,0 @@ -if 5 < x < y > z: - print("Puzzling condition") - -if a == b != c > d < e: - print("Confusing multiple conditions") diff --git a/Python/Hard/103.py b/Python/Hard/103.py deleted file mode 100644 index d6f802a4..00000000 --- a/Python/Hard/103.py +++ /dev/null @@ -1,4 +0,0 @@ -def my_function(x, y): - print(x + y) - -my_function(x = 5, 3) diff --git a/Python/Hard/106.py b/Python/Hard/106.py deleted file mode 100644 index 118f2178..00000000 --- a/Python/Hard/106.py +++ /dev/null @@ -1,2 +0,0 @@ -a = 5, b = 10, c = 15 -print(a, b, c) diff --git a/Python/Hard/107.py b/Python/Hard/107.py deleted file mode 100644 index a660e01b..00000000 --- a/Python/Hard/107.py +++ /dev/null @@ -1,19 +0,0 @@ -def check_numbers(numbers): - for num in numbers: - if num % 2 == 0: - print(f"{num} is even") - return num * 2 - else: - return num * 3 - print(f"{num} is odd") - -result = check_numbers([1, 2, 3, 4]) -print(result) - -def find_number(numbers): - for i in numbers: - if i == 5: - return i * 2 - else: - print(i) - return i + 3 diff --git a/Python/Hard/11.py b/Python/Hard/11.py deleted file mode 100644 index 4a754e82..00000000 --- a/Python/Hard/11.py +++ /dev/null @@ -1,4 +0,0 @@ -try - result = 10 / 0 -except (ZeroDivisionError) - print("Error occurred") diff --git a/Python/Hard/110.py b/Python/Hard/110.py deleted file mode 100644 index c4a8c872..00000000 --- a/Python/Hard/110.py +++ /dev/null @@ -1,3 +0,0 @@ -def add(a, b): - return a + b - result = add(1, 2) + add diff --git a/Python/Hard/114.py b/Python/Hard/114.py deleted file mode 100644 index 2ead61f0..00000000 --- a/Python/Hard/114.py +++ /dev/null @@ -1,3 +0,0 @@ - s = "hello world" - result = s.split(" ") - Result = s.split("") diff --git a/Python/Hard/118.py b/Python/Hard/118.py deleted file mode 100644 index 9bcad4bf..00000000 --- a/Python/Hard/118.py +++ /dev/null @@ -1,4 +0,0 @@ -name = "John" -lastname = "Wick" -age = 25 -print("Name: " + name + lastname ", Age: " + age "") diff --git a/Python/Hard/12.py b/Python/Hard/12.py deleted file mode 100644 index 094483e1..00000000 --- a/Python/Hard/12.py +++ /dev/null @@ -1,3 +0,0 @@ -def greet(*args, **kwargs): - print("Hello, " + args + " " + kwargs) -greet("John", last_name="Doe") diff --git a/Python/Hard/121.py b/Python/Hard/121.py deleted file mode 100644 index bf47758d..00000000 --- a/Python/Hard/121.py +++ /dev/null @@ -1,18 +0,0 @@ -message = ‘py" -print(message) - -title = "Python's "cool" feature" - -description = 'This is a Python "error example' - -sentence = “Hello, Python!” - - def add(self, a, b): - return a + b - - def add(sprint(sentence) -elf, a): - return a + 1 -class Calculator: -calc = Calculator() -print(calc.add(5, 3)) \ No newline at end of file diff --git a/Python/Hard/124.py b/Python/Hard/124.py deleted file mode 100644 index 5feff332..00000000 --- a/Python/Hard/124.py +++ /dev/null @@ -1,31 +0,0 @@ -None = "some_value" -if None == "some_value": - print("This shouldn't work, None is a keyword!") - -True = 1 -if True: - print("This will cause an error because 'True' is a reserved keyword.") - -def for(x): - return x * 2 - -result = for(5) -print(result) - -return = 10 -if return > 5: - print("You can't use 'return' as a variable name!") - - -class = "AdvancedPython" -print("This won't work because 'class' is a reserved keyword in Python.") - - def add(self, a, b): - return a + b - - def add(sprint(sentence) -elf, a): - return a + 1 -class Calculator: -calc = Calculator() -print(calc.add(5, 3)) diff --git a/Python/Hard/130.py b/Python/Hard/130.py deleted file mode 100644 index 8da31ae0..00000000 --- a/Python/Hard/130.py +++ /dev/null @@ -1,8 +0,0 @@ -def add_numbers(a, b) - result = a + b - -num1 = 5 -num2 = 10 - -print(add_numbers(num1, num2)) - diff --git a/Python/Hard/132.py b/Python/Hard/132.py deleted file mode 100644 index 51f69870..00000000 --- a/Python/Hard/132.py +++ /dev/null @@ -1,2 +0,0 @@ -Import numpy: -print(math.trunc(5.677) \ No newline at end of file diff --git a/Python/Hard/133.py b/Python/Hard/133.py deleted file mode 100644 index 4f2d90b5..00000000 --- a/Python/Hard/133.py +++ /dev/null @@ -1,21 +0,0 @@ -class Shape: - def area(self): - return "Calculating area..." - -class Circle(Shape): - - def area(self, radius): - def add(self, a, b): - return a + b - - def add(sprint(sentence) -elf, a): - return a + 1 -class Calculator: -calc = Calculator() -print(calc.add(5, 3)) -shape = Shape() -circle = Circle() - -print(shape.area()) -print(circle.area()) diff --git a/Python/Hard/136.py b/Python/Hard/136.py deleted file mode 100644 index 794b01e9..00000000 --- a/Python/Hard/136.py +++ /dev/null @@ -1,2 +0,0 @@ -numbers = [1, 2, 3, 4, 5] -print(numbers[5]) diff --git a/Python/Hard/142.py b/Python/Hard/142.py deleted file mode 100644 index 64aeff8c..00000000 --- a/Python/Hard/142.py +++ /dev/null @@ -1,3 +0,0 @@ -def add(a, b): -sum = a + b - return sum diff --git a/Python/Hard/143.py b/Python/Hard/143.py deleted file mode 100644 index 419fab52..00000000 --- a/Python/Hard/143.py +++ /dev/null @@ -1,5 +0,0 @@ -x = 5 -if x < 10: - print("x is less than 10") -else x > 10: - print("x is greater than 10") diff --git a/Python/Hard/144.py b/Python/Hard/144.py deleted file mode 100644 index e66e91d3..00000000 --- a/Python/Hard/144.py +++ /dev/null @@ -1,4 +0,0 @@ -counter = 0 -while counter = 5: - print(counter) - counter += 1 diff --git a/Python/Hard/147.py b/Python/Hard/147.py deleted file mode 100644 index eb76aaf9..00000000 --- a/Python/Hard/147.py +++ /dev/null @@ -1,2 +0,0 @@ -x = 10 -return x diff --git a/Python/Hard/148.py b/Python/Hard/148.py deleted file mode 100644 index 76ae0477..00000000 --- a/Python/Hard/148.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - print(1 / 0) -except ZeroDivisionError - print("Can't divide by zero") diff --git a/Python/Hard/150.py b/Python/Hard/150.py deleted file mode 100644 index b62480c7..00000000 --- a/Python/Hard/150.py +++ /dev/null @@ -1,18 +0,0 @@ -class Dog: - def __init__(name): - self.name = name - - def bark(): - print(self.name + " is barking") - -my_dog = Dog("Buddy") -my_dog.bark() -def add(self, a, b): - return a + b - - def add(sprint(sentence) -elf, a): - return a + 1 -class Calculator: -calc = Calculator() -print(calc.add(5, 3)) diff --git a/Python/Hard/17.py b/Python/Hard/17.py deleted file mode 100644 index 4a694033..00000000 --- a/Python/Hard/17.py +++ /dev/null @@ -1,2 +0,0 @@ -Import math: -print(math.trunc(5.677) diff --git a/Python/Hard/18.py b/Python/Hard/18.py deleted file mode 100644 index 824a011d..00000000 --- a/Python/Hard/18.py +++ /dev/null @@ -1,3 +0,0 @@ -for i in range(5) -break -print(i) diff --git a/Python/Hard/2.py b/Python/Hard/2.py deleted file mode 100644 index 96f22e93..00000000 --- a/Python/Hard/2.py +++ /dev/null @@ -1,2 +0,0 @@ -x = 10 -print(len(x)) diff --git a/Python/Hard/22.py b/Python/Hard/22.py deleted file mode 100644 index 08b50a84..00000000 --- a/Python/Hard/22.py +++ /dev/null @@ -1,8 +0,0 @@ -a=3 -b=4 -print(a+b+c) - -x = 5 -y = z - -print(x + y) diff --git a/Python/Hard/23.py b/Python/Hard/23.py deleted file mode 100644 index 3be4031f..00000000 --- a/Python/Hard/23.py +++ /dev/null @@ -1,8 +0,0 @@ -n=12 -If n%2=0: - print(‘even number’) - -num = 15 - -if num = 10: - print("Number is 10") diff --git a/Python/Hard/26.py b/Python/Hard/26.py deleted file mode 100644 index 89f4bcd7..00000000 --- a/Python/Hard/26.py +++ /dev/null @@ -1,10 +0,0 @@ -def multiply: - Return a*b -a=int(input(‘enter a num’)) -b=int(input(‘enter another number’)) - -def square(num): - return num * num - - -square diff --git a/Python/Hard/27.py b/Python/Hard/27.py deleted file mode 100644 index bf3b6b58..00000000 --- a/Python/Hard/27.py +++ /dev/null @@ -1,9 +0,0 @@ -age = 25 -message = "I am " + age + " years old." -print(message) - -age = "25" - -message = "I am " + age + " years old." - -print(message) diff --git a/Python/Hard/29.py b/Python/Hard/29.py deleted file mode 100644 index 2724d901..00000000 --- a/Python/Hard/29.py +++ /dev/null @@ -1,5 +0,0 @@ -def infinite_recursion(n): - return infinite_recursion(n + 1) - -result = infinite_recursion(0) -print(result) diff --git a/Python/Hard/3.py b/Python/Hard/3.py deleted file mode 100644 index 2b6e9d84..00000000 --- a/Python/Hard/3.py +++ /dev/null @@ -1,3 +0,0 @@ -name = "John" -age = 25 -print("Name: " + name + ", Age: " + age) diff --git a/Python/Hard/32.py b/Python/Hard/32.py deleted file mode 100644 index 08a5f6b8..00000000 --- a/Python/Hard/32.py +++ /dev/null @@ -1,7 +0,0 @@ -import sys - -sys.setrecursionlimit(10) -def recursive_function(): - recursive_function() - -recursive_function() diff --git a/Python/Hard/33.py b/Python/Hard/33.py deleted file mode 100644 index 08a5f6b8..00000000 --- a/Python/Hard/33.py +++ /dev/null @@ -1,7 +0,0 @@ -import sys - -sys.setrecursionlimit(10) -def recursive_function(): - recursive_function() - -recursive_function() diff --git a/Python/Hard/37.py b/Python/Hard/37.py deleted file mode 100644 index 5ffb9a4f..00000000 --- a/Python/Hard/37.py +++ /dev/null @@ -1,4 +0,0 @@ -def add(a, b): - return a + b - result = add(1, 2) + add - diff --git a/Python/Hard/40.py b/Python/Hard/40.py deleted file mode 100644 index 561415e8..00000000 --- a/Python/Hard/40.py +++ /dev/null @@ -1,2 +0,0 @@ -my_dict = {'a': 1, 'b': 2} -print(my_dict['c']) diff --git a/Python/Hard/41.py b/Python/Hard/41.py deleted file mode 100644 index 7f8a37cf..00000000 --- a/Python/Hard/41.py +++ /dev/null @@ -1,4 +0,0 @@ -s = "hello world" -result = s.split(" ") -Result = s.split("") - diff --git a/Python/Hard/42.py b/Python/Hard/42.py deleted file mode 100644 index fc1bdacb..00000000 --- a/Python/Hard/42.py +++ /dev/null @@ -1 +0,0 @@ -r = range(3, 10, 0) diff --git a/Python/Hard/44.py b/Python/Hard/44.py deleted file mode 100644 index 356df61a..00000000 --- a/Python/Hard/44.py +++ /dev/null @@ -1,14 +0,0 @@ -def calculate_sum(): - sum = 0 - - - numbers = [1, 2, 3, 4] - total = sum(numbers) - print("The sum of the numbers is:", total) - - - more_numbers = [10, 20, 30] - result = sum(more_numbers) - print("The result is:", result) - -calculate_sum() diff --git a/Python/Hard/48.py b/Python/Hard/48.py deleted file mode 100644 index d8cf07f6..00000000 --- a/Python/Hard/48.py +++ /dev/null @@ -1,7 +0,0 @@ -class A: - def method(): - print("Hello") - -a = A() -a.method() - diff --git a/Python/Hard/50.py b/Python/Hard/50.py deleted file mode 100644 index d8340cfa..00000000 --- a/Python/Hard/50.py +++ /dev/null @@ -1,21 +0,0 @@ -def increment_example(): - x = 10 - - - y = x++ - - - print("The value of y is:", y) - - - print("The value of x after incrementing is:", x) - -increment_example() - - -a = 7 -b = a++ - - -print("The value of b is:", b) -print("The value of a after incrementing is:", a) diff --git a/Python/Hard/52.py b/Python/Hard/52.py deleted file mode 100644 index 06de13ee..00000000 --- a/Python/Hard/52.py +++ /dev/null @@ -1,7 +0,0 @@ -x = 15 -if x > 10: - print("x is greater than 10") -else: - print("x is less than or equal to 10") -elif x == 15: - print("x is equal to 15") diff --git a/Python/Hard/55.py b/Python/Hard/55.py deleted file mode 100644 index 8a876ea9..00000000 --- a/Python/Hard/55.py +++ /dev/null @@ -1,3 +0,0 @@ -try: - value = int("abc") -print("This won't execute") diff --git a/Python/Hard/61.py b/Python/Hard/61.py deleted file mode 100644 index 961eeca6..00000000 --- a/Python/Hard/61.py +++ /dev/null @@ -1,12 +0,0 @@ -def print_numbers(): - - for i in range[1, 6]: - - print i) - - i += 1 - - print("Final value of i:", i) - - -print_numbers() diff --git a/Python/Hard/65.py b/Python/Hard/65.py deleted file mode 100644 index 95e63917..00000000 --- a/Python/Hard/65.py +++ /dev/null @@ -1,23 +0,0 @@ - -def check_numbers(): - - for i in range("5"): - - - print i - - - if i = "5": - - print("Finally reached five, which shouldn't be possible!") - - - break i - - j + 1 - - - print("Loop ended at:", i) - - -check_numbers() diff --git a/Python/Hard/69.py b/Python/Hard/69.py deleted file mode 100644 index b1b73360..00000000 --- a/Python/Hard/69.py +++ /dev/null @@ -1,28 +0,0 @@ -x = 10 -y = "5" - - -if x > 5: - if y > 3: - print("y is greater than 3") - elif x == 10: - print("x is exactly 10") - else: - print("This won't be printed, but it's here anyway") - -elif x < 5: - print("x is less than 5") - - -else: - print("x is exactly 5") - - -if x == "10": - print("x is string 10") - -if y == 5: - print("y is integer 5") - -else: - print("No match for y") diff --git a/Python/Hard/73.py b/Python/Hard/73.py deleted file mode 100644 index f13cd1f8..00000000 --- a/Python/Hard/73.py +++ /dev/null @@ -1,3 +0,0 @@ -list1 = [1, 2, 3] -list2 = [4, 5, 6] -list1 += list2() diff --git a/Python/Hard/75.py b/Python/Hard/75.py deleted file mode 100644 index fd719455..00000000 --- a/Python/Hard/75.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - result = 10 / 0 -finally: - print("This is printed after the exception") diff --git a/Python/Hard/76.py b/Python/Hard/76.py deleted file mode 100644 index 7f99ef07..00000000 --- a/Python/Hard/76.py +++ /dev/null @@ -1,16 +0,0 @@ - -x = 10 + 2 * 3 ** 2 - - -y = 5 + 3 ** 2 * 2 - (4 / 2) + 1 - - -x = "Value: " + str(x) - - -z = x + 10 * 2 - - -print("Final value of x:", x) -print("Value of y:", y) -print("Value of z:", z) \ No newline at end of file diff --git a/Python/Hard/79.py b/Python/Hard/79.py deleted file mode 100644 index eed734dc..00000000 --- a/Python/Hard/79.py +++ /dev/null @@ -1,19 +0,0 @@ -def multiply(a, b): - return a * b - - -result = multiply(2, 3) + multiply(2, '4') - - -print(result + undefined_variable) - - -if multiply(5, 0) = 0: - print("This won't print due to syntax error") - - -for i in range(5) - print("Loop iteration:", i) - - -print("Final result is:", result, "with multiplication check:", multiply(4, 'five')) diff --git a/Python/Hard/81.py b/Python/Hard/81.py deleted file mode 100644 index 5b88cf1c..00000000 --- a/Python/Hard/81.py +++ /dev/null @@ -1,24 +0,0 @@ -def outer(): - def inner(): - print(x) - inner() - - -x = "5" - - -def another_function(): - print("This is another function.") - inner() - -outer() - - -def yet_another_function(): - global x - x = x + 1 - -yet_another_function() - - -print("Final value of x is: " + x) diff --git a/Python/Hard/93.py b/Python/Hard/93.py deleted file mode 100644 index ac22c448..00000000 --- a/Python/Hard/93.py +++ /dev/null @@ -1,3 +0,0 @@ -x = 10 -y = 10 -if x is y: print("Same") diff --git a/Python/Hard/96.py b/Python/Hard/96.py deleted file mode 100644 index 76e8ff0e..00000000 --- a/Python/Hard/96.py +++ /dev/null @@ -1,10 +0,0 @@ -my_list = [1, 2, 3, 4, -5, 6, 7 8, 9] - -my_dict = { - 'key1': 1, - 'key2': 2, - 'key3': 3, - 'key4': 4 - 'key5': 5 -} diff --git a/Python/Hard/98.py b/Python/Hard/98.py deleted file mode 100644 index 2a6c4a08..00000000 --- a/Python/Hard/98.py +++ /dev/null @@ -1,5 +0,0 @@ -x = 10 -else: - print("x is something else") -x = 5 -continue diff --git a/Python/Hard/99.py b/Python/Hard/99.py deleted file mode 100644 index ca7f87a9..00000000 --- a/Python/Hard/99.py +++ /dev/null @@ -1,2 +0,0 @@ -squared = [x**2 for x in range(10) if x > 2 print(x)] -evens = [x for x in range(20) if x % 2 == 0 print(x)] diff --git a/Python/Hard/temp.txt b/Python/Hard/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/Python/Hard/temp.txt +++ /dev/null @@ -1 +0,0 @@ - From fbab2104ef73fea88e5ac377da4f8bda5a01679e Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:28:23 +0530 Subject: [PATCH 08/62] added medium level snippets --- Python/Medium/10.py | 3 +++ Python/Medium/101.py | 5 +++++ Python/Medium/103.py | 4 ++++ Python/Medium/106.py | 2 ++ Python/Medium/107.py | 19 +++++++++++++++++++ Python/Medium/11.py | 4 ++++ Python/Medium/110.py | 3 +++ Python/Medium/114.py | 3 +++ Python/Medium/118.py | 4 ++++ Python/Medium/12.py | 3 +++ Python/Medium/121.py | 18 ++++++++++++++++++ Python/Medium/124.py | 31 +++++++++++++++++++++++++++++++ Python/Medium/130.py | 8 ++++++++ Python/Medium/132.py | 2 ++ Python/Medium/133.py | 21 +++++++++++++++++++++ Python/Medium/136.py | 2 ++ Python/Medium/142.py | 3 +++ Python/Medium/143.py | 5 +++++ Python/Medium/144.py | 4 ++++ Python/Medium/147.py | 2 ++ Python/Medium/148.py | 4 ++++ Python/Medium/150.py | 18 ++++++++++++++++++ Python/Medium/17.py | 2 ++ Python/Medium/18.py | 3 +++ Python/Medium/2.py | 2 ++ Python/Medium/22.py | 8 ++++++++ Python/Medium/23.py | 8 ++++++++ Python/Medium/26.py | 10 ++++++++++ Python/Medium/27.py | 9 +++++++++ Python/Medium/29.py | 5 +++++ Python/Medium/3.py | 3 +++ Python/Medium/32.py | 7 +++++++ Python/Medium/33.py | 7 +++++++ Python/Medium/37.py | 4 ++++ Python/Medium/40.py | 2 ++ Python/Medium/41.py | 4 ++++ Python/Medium/42.py | 1 + Python/Medium/44.py | 14 ++++++++++++++ Python/Medium/48.py | 7 +++++++ Python/Medium/50.py | 21 +++++++++++++++++++++ Python/Medium/52.py | 7 +++++++ Python/Medium/55.py | 3 +++ Python/Medium/61.py | 12 ++++++++++++ Python/Medium/65.py | 23 +++++++++++++++++++++++ Python/Medium/69.py | 28 ++++++++++++++++++++++++++++ Python/Medium/73.py | 3 +++ Python/Medium/75.py | 4 ++++ Python/Medium/76.py | 16 ++++++++++++++++ Python/Medium/79.py | 19 +++++++++++++++++++ Python/Medium/81.py | 24 ++++++++++++++++++++++++ Python/Medium/93.py | 3 +++ Python/Medium/96.py | 10 ++++++++++ Python/Medium/98.py | 5 +++++ Python/Medium/99.py | 2 ++ 54 files changed, 444 insertions(+) create mode 100644 Python/Medium/10.py create mode 100644 Python/Medium/101.py create mode 100644 Python/Medium/103.py create mode 100644 Python/Medium/106.py create mode 100644 Python/Medium/107.py create mode 100644 Python/Medium/11.py create mode 100644 Python/Medium/110.py create mode 100644 Python/Medium/114.py create mode 100644 Python/Medium/118.py create mode 100644 Python/Medium/12.py create mode 100644 Python/Medium/121.py create mode 100644 Python/Medium/124.py create mode 100644 Python/Medium/130.py create mode 100644 Python/Medium/132.py create mode 100644 Python/Medium/133.py create mode 100644 Python/Medium/136.py create mode 100644 Python/Medium/142.py create mode 100644 Python/Medium/143.py create mode 100644 Python/Medium/144.py create mode 100644 Python/Medium/147.py create mode 100644 Python/Medium/148.py create mode 100644 Python/Medium/150.py create mode 100644 Python/Medium/17.py create mode 100644 Python/Medium/18.py create mode 100644 Python/Medium/2.py create mode 100644 Python/Medium/22.py create mode 100644 Python/Medium/23.py create mode 100644 Python/Medium/26.py create mode 100644 Python/Medium/27.py create mode 100644 Python/Medium/29.py create mode 100644 Python/Medium/3.py create mode 100644 Python/Medium/32.py create mode 100644 Python/Medium/33.py create mode 100644 Python/Medium/37.py create mode 100644 Python/Medium/40.py create mode 100644 Python/Medium/41.py create mode 100644 Python/Medium/42.py create mode 100644 Python/Medium/44.py create mode 100644 Python/Medium/48.py create mode 100644 Python/Medium/50.py create mode 100644 Python/Medium/52.py create mode 100644 Python/Medium/55.py create mode 100644 Python/Medium/61.py create mode 100644 Python/Medium/65.py create mode 100644 Python/Medium/69.py create mode 100644 Python/Medium/73.py create mode 100644 Python/Medium/75.py create mode 100644 Python/Medium/76.py create mode 100644 Python/Medium/79.py create mode 100644 Python/Medium/81.py create mode 100644 Python/Medium/93.py create mode 100644 Python/Medium/96.py create mode 100644 Python/Medium/98.py create mode 100644 Python/Medium/99.py diff --git a/Python/Medium/10.py b/Python/Medium/10.py new file mode 100644 index 00000000..08763d2a --- /dev/null +++ b/Python/Medium/10.py @@ -0,0 +1,3 @@ +numbers = [1, 2, 3, 4, 5] +squared = [x** for x in numbers] +print(squared) diff --git a/Python/Medium/101.py b/Python/Medium/101.py new file mode 100644 index 00000000..e549a10c --- /dev/null +++ b/Python/Medium/101.py @@ -0,0 +1,5 @@ +if 5 < x < y > z: + print("Puzzling condition") + +if a == b != c > d < e: + print("Confusing multiple conditions") diff --git a/Python/Medium/103.py b/Python/Medium/103.py new file mode 100644 index 00000000..d6f802a4 --- /dev/null +++ b/Python/Medium/103.py @@ -0,0 +1,4 @@ +def my_function(x, y): + print(x + y) + +my_function(x = 5, 3) diff --git a/Python/Medium/106.py b/Python/Medium/106.py new file mode 100644 index 00000000..118f2178 --- /dev/null +++ b/Python/Medium/106.py @@ -0,0 +1,2 @@ +a = 5, b = 10, c = 15 +print(a, b, c) diff --git a/Python/Medium/107.py b/Python/Medium/107.py new file mode 100644 index 00000000..a660e01b --- /dev/null +++ b/Python/Medium/107.py @@ -0,0 +1,19 @@ +def check_numbers(numbers): + for num in numbers: + if num % 2 == 0: + print(f"{num} is even") + return num * 2 + else: + return num * 3 + print(f"{num} is odd") + +result = check_numbers([1, 2, 3, 4]) +print(result) + +def find_number(numbers): + for i in numbers: + if i == 5: + return i * 2 + else: + print(i) + return i + 3 diff --git a/Python/Medium/11.py b/Python/Medium/11.py new file mode 100644 index 00000000..4a754e82 --- /dev/null +++ b/Python/Medium/11.py @@ -0,0 +1,4 @@ +try + result = 10 / 0 +except (ZeroDivisionError) + print("Error occurred") diff --git a/Python/Medium/110.py b/Python/Medium/110.py new file mode 100644 index 00000000..c4a8c872 --- /dev/null +++ b/Python/Medium/110.py @@ -0,0 +1,3 @@ +def add(a, b): + return a + b + result = add(1, 2) + add diff --git a/Python/Medium/114.py b/Python/Medium/114.py new file mode 100644 index 00000000..2ead61f0 --- /dev/null +++ b/Python/Medium/114.py @@ -0,0 +1,3 @@ + s = "hello world" + result = s.split(" ") + Result = s.split("") diff --git a/Python/Medium/118.py b/Python/Medium/118.py new file mode 100644 index 00000000..9bcad4bf --- /dev/null +++ b/Python/Medium/118.py @@ -0,0 +1,4 @@ +name = "John" +lastname = "Wick" +age = 25 +print("Name: " + name + lastname ", Age: " + age "") diff --git a/Python/Medium/12.py b/Python/Medium/12.py new file mode 100644 index 00000000..094483e1 --- /dev/null +++ b/Python/Medium/12.py @@ -0,0 +1,3 @@ +def greet(*args, **kwargs): + print("Hello, " + args + " " + kwargs) +greet("John", last_name="Doe") diff --git a/Python/Medium/121.py b/Python/Medium/121.py new file mode 100644 index 00000000..bf47758d --- /dev/null +++ b/Python/Medium/121.py @@ -0,0 +1,18 @@ +message = ‘py" +print(message) + +title = "Python's "cool" feature" + +description = 'This is a Python "error example' + +sentence = “Hello, Python!” + + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) \ No newline at end of file diff --git a/Python/Medium/124.py b/Python/Medium/124.py new file mode 100644 index 00000000..5feff332 --- /dev/null +++ b/Python/Medium/124.py @@ -0,0 +1,31 @@ +None = "some_value" +if None == "some_value": + print("This shouldn't work, None is a keyword!") + +True = 1 +if True: + print("This will cause an error because 'True' is a reserved keyword.") + +def for(x): + return x * 2 + +result = for(5) +print(result) + +return = 10 +if return > 5: + print("You can't use 'return' as a variable name!") + + +class = "AdvancedPython" +print("This won't work because 'class' is a reserved keyword in Python.") + + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) diff --git a/Python/Medium/130.py b/Python/Medium/130.py new file mode 100644 index 00000000..8da31ae0 --- /dev/null +++ b/Python/Medium/130.py @@ -0,0 +1,8 @@ +def add_numbers(a, b) + result = a + b + +num1 = 5 +num2 = 10 + +print(add_numbers(num1, num2)) + diff --git a/Python/Medium/132.py b/Python/Medium/132.py new file mode 100644 index 00000000..51f69870 --- /dev/null +++ b/Python/Medium/132.py @@ -0,0 +1,2 @@ +Import numpy: +print(math.trunc(5.677) \ No newline at end of file diff --git a/Python/Medium/133.py b/Python/Medium/133.py new file mode 100644 index 00000000..4f2d90b5 --- /dev/null +++ b/Python/Medium/133.py @@ -0,0 +1,21 @@ +class Shape: + def area(self): + return "Calculating area..." + +class Circle(Shape): + + def area(self, radius): + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) +shape = Shape() +circle = Circle() + +print(shape.area()) +print(circle.area()) diff --git a/Python/Medium/136.py b/Python/Medium/136.py new file mode 100644 index 00000000..794b01e9 --- /dev/null +++ b/Python/Medium/136.py @@ -0,0 +1,2 @@ +numbers = [1, 2, 3, 4, 5] +print(numbers[5]) diff --git a/Python/Medium/142.py b/Python/Medium/142.py new file mode 100644 index 00000000..64aeff8c --- /dev/null +++ b/Python/Medium/142.py @@ -0,0 +1,3 @@ +def add(a, b): +sum = a + b + return sum diff --git a/Python/Medium/143.py b/Python/Medium/143.py new file mode 100644 index 00000000..419fab52 --- /dev/null +++ b/Python/Medium/143.py @@ -0,0 +1,5 @@ +x = 5 +if x < 10: + print("x is less than 10") +else x > 10: + print("x is greater than 10") diff --git a/Python/Medium/144.py b/Python/Medium/144.py new file mode 100644 index 00000000..e66e91d3 --- /dev/null +++ b/Python/Medium/144.py @@ -0,0 +1,4 @@ +counter = 0 +while counter = 5: + print(counter) + counter += 1 diff --git a/Python/Medium/147.py b/Python/Medium/147.py new file mode 100644 index 00000000..eb76aaf9 --- /dev/null +++ b/Python/Medium/147.py @@ -0,0 +1,2 @@ +x = 10 +return x diff --git a/Python/Medium/148.py b/Python/Medium/148.py new file mode 100644 index 00000000..76ae0477 --- /dev/null +++ b/Python/Medium/148.py @@ -0,0 +1,4 @@ +try: + print(1 / 0) +except ZeroDivisionError + print("Can't divide by zero") diff --git a/Python/Medium/150.py b/Python/Medium/150.py new file mode 100644 index 00000000..b62480c7 --- /dev/null +++ b/Python/Medium/150.py @@ -0,0 +1,18 @@ +class Dog: + def __init__(name): + self.name = name + + def bark(): + print(self.name + " is barking") + +my_dog = Dog("Buddy") +my_dog.bark() +def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) diff --git a/Python/Medium/17.py b/Python/Medium/17.py new file mode 100644 index 00000000..4a694033 --- /dev/null +++ b/Python/Medium/17.py @@ -0,0 +1,2 @@ +Import math: +print(math.trunc(5.677) diff --git a/Python/Medium/18.py b/Python/Medium/18.py new file mode 100644 index 00000000..824a011d --- /dev/null +++ b/Python/Medium/18.py @@ -0,0 +1,3 @@ +for i in range(5) +break +print(i) diff --git a/Python/Medium/2.py b/Python/Medium/2.py new file mode 100644 index 00000000..96f22e93 --- /dev/null +++ b/Python/Medium/2.py @@ -0,0 +1,2 @@ +x = 10 +print(len(x)) diff --git a/Python/Medium/22.py b/Python/Medium/22.py new file mode 100644 index 00000000..08b50a84 --- /dev/null +++ b/Python/Medium/22.py @@ -0,0 +1,8 @@ +a=3 +b=4 +print(a+b+c) + +x = 5 +y = z + +print(x + y) diff --git a/Python/Medium/23.py b/Python/Medium/23.py new file mode 100644 index 00000000..3be4031f --- /dev/null +++ b/Python/Medium/23.py @@ -0,0 +1,8 @@ +n=12 +If n%2=0: + print(‘even number’) + +num = 15 + +if num = 10: + print("Number is 10") diff --git a/Python/Medium/26.py b/Python/Medium/26.py new file mode 100644 index 00000000..89f4bcd7 --- /dev/null +++ b/Python/Medium/26.py @@ -0,0 +1,10 @@ +def multiply: + Return a*b +a=int(input(‘enter a num’)) +b=int(input(‘enter another number’)) + +def square(num): + return num * num + + +square diff --git a/Python/Medium/27.py b/Python/Medium/27.py new file mode 100644 index 00000000..bf3b6b58 --- /dev/null +++ b/Python/Medium/27.py @@ -0,0 +1,9 @@ +age = 25 +message = "I am " + age + " years old." +print(message) + +age = "25" + +message = "I am " + age + " years old." + +print(message) diff --git a/Python/Medium/29.py b/Python/Medium/29.py new file mode 100644 index 00000000..2724d901 --- /dev/null +++ b/Python/Medium/29.py @@ -0,0 +1,5 @@ +def infinite_recursion(n): + return infinite_recursion(n + 1) + +result = infinite_recursion(0) +print(result) diff --git a/Python/Medium/3.py b/Python/Medium/3.py new file mode 100644 index 00000000..2b6e9d84 --- /dev/null +++ b/Python/Medium/3.py @@ -0,0 +1,3 @@ +name = "John" +age = 25 +print("Name: " + name + ", Age: " + age) diff --git a/Python/Medium/32.py b/Python/Medium/32.py new file mode 100644 index 00000000..08a5f6b8 --- /dev/null +++ b/Python/Medium/32.py @@ -0,0 +1,7 @@ +import sys + +sys.setrecursionlimit(10) +def recursive_function(): + recursive_function() + +recursive_function() diff --git a/Python/Medium/33.py b/Python/Medium/33.py new file mode 100644 index 00000000..08a5f6b8 --- /dev/null +++ b/Python/Medium/33.py @@ -0,0 +1,7 @@ +import sys + +sys.setrecursionlimit(10) +def recursive_function(): + recursive_function() + +recursive_function() diff --git a/Python/Medium/37.py b/Python/Medium/37.py new file mode 100644 index 00000000..5ffb9a4f --- /dev/null +++ b/Python/Medium/37.py @@ -0,0 +1,4 @@ +def add(a, b): + return a + b + result = add(1, 2) + add + diff --git a/Python/Medium/40.py b/Python/Medium/40.py new file mode 100644 index 00000000..561415e8 --- /dev/null +++ b/Python/Medium/40.py @@ -0,0 +1,2 @@ +my_dict = {'a': 1, 'b': 2} +print(my_dict['c']) diff --git a/Python/Medium/41.py b/Python/Medium/41.py new file mode 100644 index 00000000..7f8a37cf --- /dev/null +++ b/Python/Medium/41.py @@ -0,0 +1,4 @@ +s = "hello world" +result = s.split(" ") +Result = s.split("") + diff --git a/Python/Medium/42.py b/Python/Medium/42.py new file mode 100644 index 00000000..fc1bdacb --- /dev/null +++ b/Python/Medium/42.py @@ -0,0 +1 @@ +r = range(3, 10, 0) diff --git a/Python/Medium/44.py b/Python/Medium/44.py new file mode 100644 index 00000000..356df61a --- /dev/null +++ b/Python/Medium/44.py @@ -0,0 +1,14 @@ +def calculate_sum(): + sum = 0 + + + numbers = [1, 2, 3, 4] + total = sum(numbers) + print("The sum of the numbers is:", total) + + + more_numbers = [10, 20, 30] + result = sum(more_numbers) + print("The result is:", result) + +calculate_sum() diff --git a/Python/Medium/48.py b/Python/Medium/48.py new file mode 100644 index 00000000..d8cf07f6 --- /dev/null +++ b/Python/Medium/48.py @@ -0,0 +1,7 @@ +class A: + def method(): + print("Hello") + +a = A() +a.method() + diff --git a/Python/Medium/50.py b/Python/Medium/50.py new file mode 100644 index 00000000..d8340cfa --- /dev/null +++ b/Python/Medium/50.py @@ -0,0 +1,21 @@ +def increment_example(): + x = 10 + + + y = x++ + + + print("The value of y is:", y) + + + print("The value of x after incrementing is:", x) + +increment_example() + + +a = 7 +b = a++ + + +print("The value of b is:", b) +print("The value of a after incrementing is:", a) diff --git a/Python/Medium/52.py b/Python/Medium/52.py new file mode 100644 index 00000000..06de13ee --- /dev/null +++ b/Python/Medium/52.py @@ -0,0 +1,7 @@ +x = 15 +if x > 10: + print("x is greater than 10") +else: + print("x is less than or equal to 10") +elif x == 15: + print("x is equal to 15") diff --git a/Python/Medium/55.py b/Python/Medium/55.py new file mode 100644 index 00000000..8a876ea9 --- /dev/null +++ b/Python/Medium/55.py @@ -0,0 +1,3 @@ +try: + value = int("abc") +print("This won't execute") diff --git a/Python/Medium/61.py b/Python/Medium/61.py new file mode 100644 index 00000000..961eeca6 --- /dev/null +++ b/Python/Medium/61.py @@ -0,0 +1,12 @@ +def print_numbers(): + + for i in range[1, 6]: + + print i) + + i += 1 + + print("Final value of i:", i) + + +print_numbers() diff --git a/Python/Medium/65.py b/Python/Medium/65.py new file mode 100644 index 00000000..95e63917 --- /dev/null +++ b/Python/Medium/65.py @@ -0,0 +1,23 @@ + +def check_numbers(): + + for i in range("5"): + + + print i + + + if i = "5": + + print("Finally reached five, which shouldn't be possible!") + + + break i + + j + 1 + + + print("Loop ended at:", i) + + +check_numbers() diff --git a/Python/Medium/69.py b/Python/Medium/69.py new file mode 100644 index 00000000..b1b73360 --- /dev/null +++ b/Python/Medium/69.py @@ -0,0 +1,28 @@ +x = 10 +y = "5" + + +if x > 5: + if y > 3: + print("y is greater than 3") + elif x == 10: + print("x is exactly 10") + else: + print("This won't be printed, but it's here anyway") + +elif x < 5: + print("x is less than 5") + + +else: + print("x is exactly 5") + + +if x == "10": + print("x is string 10") + +if y == 5: + print("y is integer 5") + +else: + print("No match for y") diff --git a/Python/Medium/73.py b/Python/Medium/73.py new file mode 100644 index 00000000..f13cd1f8 --- /dev/null +++ b/Python/Medium/73.py @@ -0,0 +1,3 @@ +list1 = [1, 2, 3] +list2 = [4, 5, 6] +list1 += list2() diff --git a/Python/Medium/75.py b/Python/Medium/75.py new file mode 100644 index 00000000..fd719455 --- /dev/null +++ b/Python/Medium/75.py @@ -0,0 +1,4 @@ +try: + result = 10 / 0 +finally: + print("This is printed after the exception") diff --git a/Python/Medium/76.py b/Python/Medium/76.py new file mode 100644 index 00000000..7f99ef07 --- /dev/null +++ b/Python/Medium/76.py @@ -0,0 +1,16 @@ + +x = 10 + 2 * 3 ** 2 + + +y = 5 + 3 ** 2 * 2 - (4 / 2) + 1 + + +x = "Value: " + str(x) + + +z = x + 10 * 2 + + +print("Final value of x:", x) +print("Value of y:", y) +print("Value of z:", z) \ No newline at end of file diff --git a/Python/Medium/79.py b/Python/Medium/79.py new file mode 100644 index 00000000..eed734dc --- /dev/null +++ b/Python/Medium/79.py @@ -0,0 +1,19 @@ +def multiply(a, b): + return a * b + + +result = multiply(2, 3) + multiply(2, '4') + + +print(result + undefined_variable) + + +if multiply(5, 0) = 0: + print("This won't print due to syntax error") + + +for i in range(5) + print("Loop iteration:", i) + + +print("Final result is:", result, "with multiplication check:", multiply(4, 'five')) diff --git a/Python/Medium/81.py b/Python/Medium/81.py new file mode 100644 index 00000000..5b88cf1c --- /dev/null +++ b/Python/Medium/81.py @@ -0,0 +1,24 @@ +def outer(): + def inner(): + print(x) + inner() + + +x = "5" + + +def another_function(): + print("This is another function.") + inner() + +outer() + + +def yet_another_function(): + global x + x = x + 1 + +yet_another_function() + + +print("Final value of x is: " + x) diff --git a/Python/Medium/93.py b/Python/Medium/93.py new file mode 100644 index 00000000..ac22c448 --- /dev/null +++ b/Python/Medium/93.py @@ -0,0 +1,3 @@ +x = 10 +y = 10 +if x is y: print("Same") diff --git a/Python/Medium/96.py b/Python/Medium/96.py new file mode 100644 index 00000000..76e8ff0e --- /dev/null +++ b/Python/Medium/96.py @@ -0,0 +1,10 @@ +my_list = [1, 2, 3, 4, +5, 6, 7 8, 9] + +my_dict = { + 'key1': 1, + 'key2': 2, + 'key3': 3, + 'key4': 4 + 'key5': 5 +} diff --git a/Python/Medium/98.py b/Python/Medium/98.py new file mode 100644 index 00000000..2a6c4a08 --- /dev/null +++ b/Python/Medium/98.py @@ -0,0 +1,5 @@ +x = 10 +else: + print("x is something else") +x = 5 +continue diff --git a/Python/Medium/99.py b/Python/Medium/99.py new file mode 100644 index 00000000..ca7f87a9 --- /dev/null +++ b/Python/Medium/99.py @@ -0,0 +1,2 @@ +squared = [x**2 for x in range(10) if x > 2 print(x)] +evens = [x for x in range(20) if x % 2 == 0 print(x)] From 0fc48da66240c9008a7658ee6879d910de0c03e4 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:29:22 +0530 Subject: [PATCH 09/62] Create temp.txt --- Python/Hard/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python/Hard/temp.txt diff --git a/Python/Hard/temp.txt b/Python/Hard/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python/Hard/temp.txt @@ -0,0 +1 @@ + From 3e1dce85cbfdb6d913a1f10763f221b9d695856e Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:30:19 +0530 Subject: [PATCH 10/62] hard level uploaded --- Python/Hard/1.py | 9 +++++++++ Python/Hard/10.py | 6 ++++++ Python/Hard/11.py | 3 +++ Python/Hard/12.py | 4 ++++ Python/Hard/13.py | 3 +++ Python/Hard/14.py | 6 ++++++ Python/Hard/16.py | 5 +++++ Python/Hard/17.py | 7 +++++++ Python/Hard/18.py | 8 ++++++++ Python/Hard/19.py | 10 ++++++++++ Python/Hard/2.py | 3 +++ Python/Hard/20.py | 4 ++++ Python/Hard/21.py | 8 ++++++++ Python/Hard/22.py | 6 ++++++ Python/Hard/23.py | 10 ++++++++++ Python/Hard/24.py | 3 +++ Python/Hard/25.py | 5 +++++ Python/Hard/26.py | 4 ++++ Python/Hard/27.py | 8 ++++++++ Python/Hard/28.py | 4 ++++ Python/Hard/29.py | 5 +++++ Python/Hard/3.py | 3 +++ Python/Hard/30.py | 5 +++++ Python/Hard/31.py | 3 +++ Python/Hard/32.py | 3 +++ Python/Hard/33.py | 5 +++++ Python/Hard/34.py | 7 +++++++ Python/Hard/35.py | 4 ++++ Python/Hard/36.py | 6 ++++++ Python/Hard/37.py | 7 +++++++ Python/Hard/38.py | 3 +++ Python/Hard/39.py | 6 ++++++ Python/Hard/4.py | 4 ++++ Python/Hard/40.py | 4 ++++ Python/Hard/41.py | 2 ++ Python/Hard/42.py | 6 ++++++ Python/Hard/43.py | 5 +++++ Python/Hard/44.py | 2 ++ Python/Hard/45.py | 4 ++++ Python/Hard/46.py | 11 +++++++++++ Python/Hard/47.py | 11 +++++++++++ Python/Hard/48.py | 12 ++++++++++++ Python/Hard/49.py | 24 ++++++++++++++++++++++++ Python/Hard/5.py | 4 ++++ Python/Hard/50.py | 13 +++++++++++++ Python/Hard/51.py | 24 ++++++++++++++++++++++++ Python/Hard/52.py | 17 +++++++++++++++++ Python/Hard/6.py | 3 +++ Python/Hard/7.py | 5 +++++ Python/Hard/8.py | 4 ++++ Python/Hard/9.py | 5 +++++ 51 files changed, 333 insertions(+) create mode 100644 Python/Hard/1.py create mode 100644 Python/Hard/10.py create mode 100644 Python/Hard/11.py create mode 100644 Python/Hard/12.py create mode 100644 Python/Hard/13.py create mode 100644 Python/Hard/14.py create mode 100644 Python/Hard/16.py create mode 100644 Python/Hard/17.py create mode 100644 Python/Hard/18.py create mode 100644 Python/Hard/19.py create mode 100644 Python/Hard/2.py create mode 100644 Python/Hard/20.py create mode 100644 Python/Hard/21.py create mode 100644 Python/Hard/22.py create mode 100644 Python/Hard/23.py create mode 100644 Python/Hard/24.py create mode 100644 Python/Hard/25.py create mode 100644 Python/Hard/26.py create mode 100644 Python/Hard/27.py create mode 100644 Python/Hard/28.py create mode 100644 Python/Hard/29.py create mode 100644 Python/Hard/3.py create mode 100644 Python/Hard/30.py create mode 100644 Python/Hard/31.py create mode 100644 Python/Hard/32.py create mode 100644 Python/Hard/33.py create mode 100644 Python/Hard/34.py create mode 100644 Python/Hard/35.py create mode 100644 Python/Hard/36.py create mode 100644 Python/Hard/37.py create mode 100644 Python/Hard/38.py create mode 100644 Python/Hard/39.py create mode 100644 Python/Hard/4.py create mode 100644 Python/Hard/40.py create mode 100644 Python/Hard/41.py create mode 100644 Python/Hard/42.py create mode 100644 Python/Hard/43.py create mode 100644 Python/Hard/44.py create mode 100644 Python/Hard/45.py create mode 100644 Python/Hard/46.py create mode 100644 Python/Hard/47.py create mode 100644 Python/Hard/48.py create mode 100644 Python/Hard/49.py create mode 100644 Python/Hard/5.py create mode 100644 Python/Hard/50.py create mode 100644 Python/Hard/51.py create mode 100644 Python/Hard/52.py create mode 100644 Python/Hard/6.py create mode 100644 Python/Hard/7.py create mode 100644 Python/Hard/8.py create mode 100644 Python/Hard/9.py diff --git a/Python/Hard/1.py b/Python/Hard/1.py new file mode 100644 index 00000000..63d4103a --- /dev/null +++ b/Python/Hard/1.py @@ -0,0 +1,9 @@ +def calculate_average(numbers): + total_sum = 0 + for number in numbers: + total_sum += number + average = total_sum / (len(numbers) - 1) + return average +numbers = [10, 20, 30, 40, 50] +avg = calculate_average(numbers) +print("The average is:", avg) \ No newline at end of file diff --git a/Python/Hard/10.py b/Python/Hard/10.py new file mode 100644 index 00000000..517a628e --- /dev/null +++ b/Python/Hard/10.py @@ -0,0 +1,6 @@ +list1 = [1, 2, 3] +list2 = [4, 5] +list3 = list1 +list3 += list2 +print("list1:", list1) +print("list3:", list3) diff --git a/Python/Hard/11.py b/Python/Hard/11.py new file mode 100644 index 00000000..9e9e16d2 --- /dev/null +++ b/Python/Hard/11.py @@ -0,0 +1,3 @@ +sequence = [1, 2, 3, 4, 5] +reversed_sequence = sequence[::0] +print(reversed_sequence) diff --git a/Python/Hard/12.py b/Python/Hard/12.py new file mode 100644 index 00000000..cabea98c --- /dev/null +++ b/Python/Hard/12.py @@ -0,0 +1,4 @@ +list1 = [1, 2, 3] +tuple1 = (4, 5, 6) +concatenated = list1 + tuple1 +print(concatenated) diff --git a/Python/Hard/13.py b/Python/Hard/13.py new file mode 100644 index 00000000..2dcf6e60 --- /dev/null +++ b/Python/Hard/13.py @@ -0,0 +1,3 @@ +sequence = [0] * 3 +sequence[0] = [1, 2, 3] * 2 +print(sequence) diff --git a/Python/Hard/14.py b/Python/Hard/14.py new file mode 100644 index 00000000..91e00394 --- /dev/null +++ b/Python/Hard/14.py @@ -0,0 +1,6 @@ +string = "hello world" +substring = "world" +if string == substring: + print("Substring found!") +else: + print("Substring not found!") diff --git a/Python/Hard/16.py b/Python/Hard/16.py new file mode 100644 index 00000000..a2670a70 --- /dev/null +++ b/Python/Hard/16.py @@ -0,0 +1,5 @@ +def build_sentence(subject, **words): + sentence = subject + ' ' + words['verb'] + ' ' + words['object'] + return sentence +print(build_sentence("The cat", verb="eats", adjective="big", +object="fish")) diff --git a/Python/Hard/17.py b/Python/Hard/17.py new file mode 100644 index 00000000..c7cd6d65 --- /dev/null +++ b/Python/Hard/17.py @@ -0,0 +1,7 @@ +class Animal: + def __init__(self, name): + self.name = name + def __repr__(self): + return f"Animal(name={self.name})" +dog = Animal('Rex') +print(dog) diff --git a/Python/Hard/18.py b/Python/Hard/18.py new file mode 100644 index 00000000..c1013c21 --- /dev/null +++ b/Python/Hard/18.py @@ -0,0 +1,8 @@ +class CustomError(Exception): + def __init__(self, message, code): + self.message = message + self.code = code +try: + raise CustomError("Something went wrong", 404) +except CustomError as e: + print(e.message + " with error code " + e.code) \ No newline at end of file diff --git a/Python/Hard/19.py b/Python/Hard/19.py new file mode 100644 index 00000000..2c5abebb --- /dev/null +++ b/Python/Hard/19.py @@ -0,0 +1,10 @@ +class Car: + def __init__(self, model, year): + self.model = model + self.year = year + def display(self): + print(f"The car is a {self.model} from {self.year}") +my_car = Car("Toyota", 2020) +print(my_car.year) +my_car.year = "2021" +my_car.display() diff --git a/Python/Hard/2.py b/Python/Hard/2.py new file mode 100644 index 00000000..9de04523 --- /dev/null +++ b/Python/Hard/2.py @@ -0,0 +1,3 @@ +numbers = [1, 2, 3, 4, 5, 6, 7, 8] +squares_of_evens = (x**2 for x in numbers if x % 2 != 0) +print(list(squares_of_evens)) \ No newline at end of file diff --git a/Python/Hard/20.py b/Python/Hard/20.py new file mode 100644 index 00000000..73c89f85 --- /dev/null +++ b/Python/Hard/20.py @@ -0,0 +1,4 @@ +with open('output.txt', 'w') as f: + f.write("This is the first line.") + f.flush() +f.write("This is the second line.") diff --git a/Python/Hard/21.py b/Python/Hard/21.py new file mode 100644 index 00000000..02614880 --- /dev/null +++ b/Python/Hard/21.py @@ -0,0 +1,8 @@ +def sub_generator(): + yield from range(3) +def main_generator(): + yield "Start" + yield sub_generator() + yield "End" +for value in main_generator(): + print(value) \ No newline at end of file diff --git a/Python/Hard/22.py b/Python/Hard/22.py new file mode 100644 index 00000000..07c84f12 --- /dev/null +++ b/Python/Hard/22.py @@ -0,0 +1,6 @@ +import module_b +def func_a(): + print("Function A") +import module_a +def func_b(): + module_a.func_a() \ No newline at end of file diff --git a/Python/Hard/23.py b/Python/Hard/23.py new file mode 100644 index 00000000..65c912b1 --- /dev/null +++ b/Python/Hard/23.py @@ -0,0 +1,10 @@ +def divide(a, b): + try: + return a / b + except ZeroDivisionError as e: + print("Cannot divide by zero:", e) + raise ValueError("Invalid division") +try: + result = divide(10, 0) +except ValueError as e: + print("Caught ValueError:", e) diff --git a/Python/Hard/24.py b/Python/Hard/24.py new file mode 100644 index 00000000..e0e2f98a --- /dev/null +++ b/Python/Hard/24.py @@ -0,0 +1,3 @@ +numbers = [1, 2, 3, "four", 5] +max_value = max(numbers) +print(f"The maximum value is: {max_value}") diff --git a/Python/Hard/25.py b/Python/Hard/25.py new file mode 100644 index 00000000..973d5649 --- /dev/null +++ b/Python/Hard/25.py @@ -0,0 +1,5 @@ +def multiply_by_two(x): + return x * 2 +numbers = [1, 2, 3, 4, 5] +result = map(multiply_by_two, numbers) +print(result[0]) \ No newline at end of file diff --git a/Python/Hard/26.py b/Python/Hard/26.py new file mode 100644 index 00000000..d0a13655 --- /dev/null +++ b/Python/Hard/26.py @@ -0,0 +1,4 @@ +from datetime import datetime +date_str = "2024-02-30" +date = datetime.strptime(date_str, "%Y-%m-%d") +print(f"Parsed date: {date}") diff --git a/Python/Hard/27.py b/Python/Hard/27.py new file mode 100644 index 00000000..54968537 --- /dev/null +++ b/Python/Hard/27.py @@ -0,0 +1,8 @@ +import os +file_name = "data.txt" +if os.path.exists(file_name): + os.remove(file_name) + print(f"{file_name} removed successfully.") +else: + print(f"{file_name} does not exist.") +os.remove(file_name) \ No newline at end of file diff --git a/Python/Hard/28.py b/Python/Hard/28.py new file mode 100644 index 00000000..6d19e890 --- /dev/null +++ b/Python/Hard/28.py @@ -0,0 +1,4 @@ +import random +numbers = [1, 2, 3, 4, 5] +sample = random.sample(numbers, 6) +print(sample) diff --git a/Python/Hard/29.py b/Python/Hard/29.py new file mode 100644 index 00000000..8b8eae08 --- /dev/null +++ b/Python/Hard/29.py @@ -0,0 +1,5 @@ +names = ["Alice", "Bob", "Charlie"] +ages = [25, 30] +zipped = zip(names, ages) +for name, age in zipped: + print(f"{name} is {age} years old.") \ No newline at end of file diff --git a/Python/Hard/3.py b/Python/Hard/3.py new file mode 100644 index 00000000..7af47cd3 --- /dev/null +++ b/Python/Hard/3.py @@ -0,0 +1,3 @@ +numbers = [1, 2, 3, 4, 5, 6, 7, 8] +even_numbers = [x for x in numbers if x % 2 != 0] +print(even_numbers) diff --git a/Python/Hard/30.py b/Python/Hard/30.py new file mode 100644 index 00000000..05a6664c --- /dev/null +++ b/Python/Hard/30.py @@ -0,0 +1,5 @@ +import json +json_data = '{"name": "John", "age": 30, "active": true}' +data = json.loads(json_data) +if data['active'] == "true": + print(f"{data['name']} is active.") diff --git a/Python/Hard/31.py b/Python/Hard/31.py new file mode 100644 index 00000000..5182d02e --- /dev/null +++ b/Python/Hard/31.py @@ -0,0 +1,3 @@ +items = [3, "banana", 2, "apple"] +sorted_items = sorted(items) +print(sorted_items) diff --git a/Python/Hard/32.py b/Python/Hard/32.py new file mode 100644 index 00000000..2251178b --- /dev/null +++ b/Python/Hard/32.py @@ -0,0 +1,3 @@ +numbers = [0, 1, 2, 3, 4, 5] +result = filter(lambda x: x % 2, numbers) +print(list(result)) \ No newline at end of file diff --git a/Python/Hard/33.py b/Python/Hard/33.py new file mode 100644 index 00000000..c598b9f7 --- /dev/null +++ b/Python/Hard/33.py @@ -0,0 +1,5 @@ +numbers = [1, 2, 3, 0] +if all(numbers): + print("All numbers are non-zero.") +else: + print("There are some zeroes.") \ No newline at end of file diff --git a/Python/Hard/34.py b/Python/Hard/34.py new file mode 100644 index 00000000..68fcbb3b --- /dev/null +++ b/Python/Hard/34.py @@ -0,0 +1,7 @@ +import math +result = math.pow(2, 3) +print(result) +if result == 8: + print("The result is 8.") +else: + print("The result is not 8.") diff --git a/Python/Hard/35.py b/Python/Hard/35.py new file mode 100644 index 00000000..807d353a --- /dev/null +++ b/Python/Hard/35.py @@ -0,0 +1,4 @@ +import time +for i in range(5): + print(f"Sleeping for {i} seconds.") + time.sleep(i) diff --git a/Python/Hard/36.py b/Python/Hard/36.py new file mode 100644 index 00000000..c30193ca --- /dev/null +++ b/Python/Hard/36.py @@ -0,0 +1,6 @@ +def sum_even_numbers(n): + result = 0 + for i in range(1, n+1): + if i % 2 == 1: + result += i + return result diff --git a/Python/Hard/37.py b/Python/Hard/37.py new file mode 100644 index 00000000..eb447794 --- /dev/null +++ b/Python/Hard/37.py @@ -0,0 +1,7 @@ +class Rectangle: + def __init__(self, length, width): + self.l = length + self.width = width + + def area(): + return self.l * width \ No newline at end of file diff --git a/Python/Hard/38.py b/Python/Hard/38.py new file mode 100644 index 00000000..0ed3f1ba --- /dev/null +++ b/Python/Hard/38.py @@ -0,0 +1,3 @@ +import math +def find_root(x): + return math.sqrt(x if x > 0 else 'undefined') \ No newline at end of file diff --git a/Python/Hard/39.py b/Python/Hard/39.py new file mode 100644 index 00000000..e941beb2 --- /dev/null +++ b/Python/Hard/39.py @@ -0,0 +1,6 @@ +def fibonacci(n): + a = 0, b = 1 + for i in range(n): + print a + a, b = b, a+b + return a diff --git a/Python/Hard/4.py b/Python/Hard/4.py new file mode 100644 index 00000000..61c36b9d --- /dev/null +++ b/Python/Hard/4.py @@ -0,0 +1,4 @@ +set_a = {1, 2, 3, 4} +set_b = {3, 4, 5, 6} +common_elements = set_a | set_b +print("Common elements:", common_elements) \ No newline at end of file diff --git a/Python/Hard/40.py b/Python/Hard/40.py new file mode 100644 index 00000000..7fbe14c3 --- /dev/null +++ b/Python/Hard/40.py @@ -0,0 +1,4 @@ +def merge_dicts(dict1, dict2): + for key in dict1.keys(): + dict1[key] = dict2[key] + return dict1 diff --git a/Python/Hard/41.py b/Python/Hard/41.py new file mode 100644 index 00000000..bece5fd5 --- /dev/null +++ b/Python/Hard/41.py @@ -0,0 +1,2 @@ +def check_palindrome(s): + return s == s[::-1].lower() diff --git a/Python/Hard/42.py b/Python/Hard/42.py new file mode 100644 index 00000000..6a89a48c --- /dev/null +++ b/Python/Hard/42.py @@ -0,0 +1,6 @@ +def find_minimum(nums): + min = nums[0] + for i in range(1, len(nums)): + if nums[i] > min: + min = nums[i] + return min diff --git a/Python/Hard/43.py b/Python/Hard/43.py new file mode 100644 index 00000000..0ef8ff96 --- /dev/null +++ b/Python/Hard/43.py @@ -0,0 +1,5 @@ +def calculate_mean(lst): + total = sum(lst) + return total / len(lst) + except ZeroDivisionError: + return 0 diff --git a/Python/Hard/44.py b/Python/Hard/44.py new file mode 100644 index 00000000..636354f5 --- /dev/null +++ b/Python/Hard/44.py @@ -0,0 +1,2 @@ +def concatenate_strings(s1, s2): + return s1 + s2 + 5 diff --git a/Python/Hard/45.py b/Python/Hard/45.py new file mode 100644 index 00000000..b7fd5073 --- /dev/null +++ b/Python/Hard/45.py @@ -0,0 +1,4 @@ +matrix = [[1, 2], [3, 4], [5, 6]] +for i in range(3): + for j in range(3): + print(matrix[i][j]) diff --git a/Python/Hard/46.py b/Python/Hard/46.py new file mode 100644 index 00000000..1905a763 --- /dev/null +++ b/Python/Hard/46.py @@ -0,0 +1,11 @@ +def binary_search(arr, left, right, target: + if right >= left: + mid = (left + right) / 2 + if arr[mid] == target: + return mid + elif arr[mid] > target: + return binary_search(arr, left, mid - 1, target) + else: + return binary_search(arr, mid + 1, right, target) + else: + return -1 \ No newline at end of file diff --git a/Python/Hard/47.py b/Python/Hard/47.py new file mode 100644 index 00000000..f7514cad --- /dev/null +++ b/Python/Hard/47.py @@ -0,0 +1,11 @@ +def dfs(graph, start): + stack = [start] + visited = set() + while stack: + node = stack.pop(0) + if node not visited: + visited.add(node) + stack.extend(graph[node]) + return visited +graph = {1: [2, 3], 2: [4], 3: [4], 4: []} +print(dfs(graph, 1)) diff --git a/Python/Hard/48.py b/Python/Hard/48.py new file mode 100644 index 00000000..55eeddfc --- /dev/null +++ b/Python/Hard/48.py @@ -0,0 +1,12 @@ +def heapify(arr, n, i): + largest = i + left = 2 * i + 1 + right = 2 * i + 2 + + if left < n and arr[left] > arr[largest]: + largest = left + if right < n and arr[right] < arr[largest]: + largest = right + if largest != i: + arr[i], arr[largest] = arr[largest], arr[i] + heapify(arr, n, largest) diff --git a/Python/Hard/49.py b/Python/Hard/49.py new file mode 100644 index 00000000..3c53cf50 --- /dev/null +++ b/Python/Hard/49.py @@ -0,0 +1,24 @@ +def merge_sort(arr): + if len(arr) > 1: + mid = len(arr) // 2 + left = arr[:mid] + right = arr[mid:] + merge_sort(left) + merge_sort(right) + i = j = k = 0 + while i < len(left) and j < len(right): + if left[i] < right[j]: + arr[k] = left[j] + i += 1 + else: + arr[k] = right[j] + j += 1 + k += 1 + while i < len(left): + arr[k] = left[i] + i += 1 + k += 1 + while j < len(right): + arr[k] = right[j] + j += 1 + k += 1 \ No newline at end of file diff --git a/Python/Hard/5.py b/Python/Hard/5.py new file mode 100644 index 00000000..308ec521 --- /dev/null +++ b/Python/Hard/5.py @@ -0,0 +1,4 @@ +set_a = {1, 2, 3, 4} +set_b = {3, 4, 5, 6} +difference_elements = set_a - set_b +print("Elements in set_b but not in set_a:", difference_elements) \ No newline at end of file diff --git a/Python/Hard/50.py b/Python/Hard/50.py new file mode 100644 index 00000000..5d9dc139 --- /dev/null +++ b/Python/Hard/50.py @@ -0,0 +1,13 @@ +def floyd_warshall(graph): + dist = list(map(lambda i: list(map(lambda j: j, i)), graph)) + V = len(graph) + for k in range(V): + for i in range(V): + for j in range(V) + dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) + return dist +graph = [[0, 3, float('inf'), 7], + [8, 0, 2, float('inf')], + [5, float('inf'), 0, 1], + [2, float('inf'), float('inf'), 0]] +print(floyd_warshall(graph)) \ No newline at end of file diff --git a/Python/Hard/51.py b/Python/Hard/51.py new file mode 100644 index 00000000..a674cc93 --- /dev/null +++ b/Python/Hard/51.py @@ -0,0 +1,24 @@ +class TrieNode: + def __init__(self): + self.children = {} + self.is_end_of_word = False +class Trie: + def __init__(self): + self.root = TrieNode() + def insert(self, word): + node = self.root + for char in word: + if char not in node.children: + node.children[char] = TrieNode + node = node.children[char] + node.is_end_of_word = True + def search(self, word): + node = self.root + for char in word: + if char not in node.children: + return False + node = node.children[char] + return node.is_end_of_word +trie = Trie() +trie.insert("hello") +print(trie.search("hello")) diff --git a/Python/Hard/52.py b/Python/Hard/52.py new file mode 100644 index 00000000..d3c316ad --- /dev/null +++ b/Python/Hard/52.py @@ -0,0 +1,17 @@ +def bfs(graph, start): + visited = set() + queue = [(start, 0)] + level = {} + while queue: + node, depth = queue.pop() + if node not in visited: + visited.add(node) + level[node] = depth + + for neighbor in graph[node]: + if neighbor not in visited: + queue.append((neighbor, depth)) + return level + +graph = {1: [2, 3], 2: [4], 3: [5], 4: [], 5: []} +print(bfs(graph, 1)) \ No newline at end of file diff --git a/Python/Hard/6.py b/Python/Hard/6.py new file mode 100644 index 00000000..b01fc102 --- /dev/null +++ b/Python/Hard/6.py @@ -0,0 +1,3 @@ +numbers = [10, 20, 30, 40] +numbers[len(numbers)] = 100 +print(numbers) diff --git a/Python/Hard/7.py b/Python/Hard/7.py new file mode 100644 index 00000000..d1323646 --- /dev/null +++ b/Python/Hard/7.py @@ -0,0 +1,5 @@ +numbers = [1, 2, 3, 4, 5] +for num in numbers: + if num % 2 == 0: + numbers.remove(num) +print(numbers) \ No newline at end of file diff --git a/Python/Hard/8.py b/Python/Hard/8.py new file mode 100644 index 00000000..b1ef36ac --- /dev/null +++ b/Python/Hard/8.py @@ -0,0 +1,4 @@ +list1 = [1, 2, 3] +list2 = [4, 5] +list1.extend(list2) +print(list1) diff --git a/Python/Hard/9.py b/Python/Hard/9.py new file mode 100644 index 00000000..c357bb0c --- /dev/null +++ b/Python/Hard/9.py @@ -0,0 +1,5 @@ +list1 = [1, 2, 3] +list2 = list1 +list2.append(4) +print("list1:", list1) +print("list2:", list2) From 3e46bdd489256700a1877b53f8cc91aad35252a9 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:39:08 +0530 Subject: [PATCH 11/62] Create temp.txt --- Python2/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python2/temp.txt diff --git a/Python2/temp.txt b/Python2/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python2/temp.txt @@ -0,0 +1 @@ + From 43c23561407ab333ca91cf4ae0bc84c74c2f00a3 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:39:28 +0530 Subject: [PATCH 12/62] Create temp.txt --- Python2/Easy/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python2/Easy/temp.txt diff --git a/Python2/Easy/temp.txt b/Python2/Easy/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python2/Easy/temp.txt @@ -0,0 +1 @@ + From ef9fab60ccd649b70f5208510a63e5b93db5cbbe Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:39:42 +0530 Subject: [PATCH 13/62] Create temp.txt --- Python2/Medium/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python2/Medium/temp.txt diff --git a/Python2/Medium/temp.txt b/Python2/Medium/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python2/Medium/temp.txt @@ -0,0 +1 @@ + From a6280e81aac3a17164f3b089fc7de365e3f43b04 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:39:58 +0530 Subject: [PATCH 14/62] Create temp.txt --- Python2/Hard/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Python2/Hard/temp.txt diff --git a/Python2/Hard/temp.txt b/Python2/Hard/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python2/Hard/temp.txt @@ -0,0 +1 @@ + From f924d3847e2a98ee50d7c65f5bf0d3d292da0d94 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:44:26 +0530 Subject: [PATCH 15/62] Easy level --- Python2/Easy/1.py | 8 ++++++++ Python2/Easy/10.py | 12 ++++++++++++ Python2/Easy/11.py | 9 +++++++++ Python2/Easy/12.py | 12 ++++++++++++ Python2/Easy/13.py | 8 ++++++++ Python2/Easy/14.py | 5 +++++ Python2/Easy/15.py | 7 +++++++ Python2/Easy/16.py | 8 ++++++++ Python2/Easy/17.py | 15 +++++++++++++++ Python2/Easy/18.py | 8 ++++++++ Python2/Easy/19.py | 9 +++++++++ Python2/Easy/2.py | 5 +++++ Python2/Easy/20.py | 9 +++++++++ Python2/Easy/21.py | 8 ++++++++ Python2/Easy/22.py | 12 ++++++++++++ Python2/Easy/23.py | 9 +++++++++ Python2/Easy/24.py | 10 ++++++++++ Python2/Easy/25.py | 5 +++++ Python2/Easy/26.py | 9 +++++++++ Python2/Easy/27.py | 10 ++++++++++ Python2/Easy/28.py | 9 +++++++++ Python2/Easy/29.py | 18 ++++++++++++++++++ Python2/Easy/3.py | 7 +++++++ Python2/Easy/30.py | 8 ++++++++ Python2/Easy/31.py | 9 +++++++++ Python2/Easy/32.py | 14 ++++++++++++++ Python2/Easy/33.py | 4 ++++ Python2/Easy/34.py | 5 +++++ Python2/Easy/35.py | 9 +++++++++ Python2/Easy/36.py | 6 ++++++ Python2/Easy/37.py | 2 ++ Python2/Easy/38.py | 4 ++++ Python2/Easy/39.py | 3 +++ Python2/Easy/4.py | 8 ++++++++ Python2/Easy/40.py | 6 ++++++ Python2/Easy/41.py | 10 ++++++++++ Python2/Easy/42.py | 9 +++++++++ Python2/Easy/43.py | 7 +++++++ Python2/Easy/44.py | 8 ++++++++ Python2/Easy/45.py | 8 ++++++++ Python2/Easy/46.py | 5 +++++ Python2/Easy/47.py | 7 +++++++ Python2/Easy/48.py | 11 +++++++++++ Python2/Easy/49.py | 8 ++++++++ Python2/Easy/5.py | 16 ++++++++++++++++ Python2/Easy/50.py | 4 ++++ Python2/Easy/6.py | 8 ++++++++ Python2/Easy/7.py | 9 +++++++++ Python2/Easy/8.py | 9 +++++++++ Python2/Easy/9.py | 8 ++++++++ 50 files changed, 417 insertions(+) create mode 100644 Python2/Easy/1.py create mode 100644 Python2/Easy/10.py create mode 100644 Python2/Easy/11.py create mode 100644 Python2/Easy/12.py create mode 100644 Python2/Easy/13.py create mode 100644 Python2/Easy/14.py create mode 100644 Python2/Easy/15.py create mode 100644 Python2/Easy/16.py create mode 100644 Python2/Easy/17.py create mode 100644 Python2/Easy/18.py create mode 100644 Python2/Easy/19.py create mode 100644 Python2/Easy/2.py create mode 100644 Python2/Easy/20.py create mode 100644 Python2/Easy/21.py create mode 100644 Python2/Easy/22.py create mode 100644 Python2/Easy/23.py create mode 100644 Python2/Easy/24.py create mode 100644 Python2/Easy/25.py create mode 100644 Python2/Easy/26.py create mode 100644 Python2/Easy/27.py create mode 100644 Python2/Easy/28.py create mode 100644 Python2/Easy/29.py create mode 100644 Python2/Easy/3.py create mode 100644 Python2/Easy/30.py create mode 100644 Python2/Easy/31.py create mode 100644 Python2/Easy/32.py create mode 100644 Python2/Easy/33.py create mode 100644 Python2/Easy/34.py create mode 100644 Python2/Easy/35.py create mode 100644 Python2/Easy/36.py create mode 100644 Python2/Easy/37.py create mode 100644 Python2/Easy/38.py create mode 100644 Python2/Easy/39.py create mode 100644 Python2/Easy/4.py create mode 100644 Python2/Easy/40.py create mode 100644 Python2/Easy/41.py create mode 100644 Python2/Easy/42.py create mode 100644 Python2/Easy/43.py create mode 100644 Python2/Easy/44.py create mode 100644 Python2/Easy/45.py create mode 100644 Python2/Easy/46.py create mode 100644 Python2/Easy/47.py create mode 100644 Python2/Easy/48.py create mode 100644 Python2/Easy/49.py create mode 100644 Python2/Easy/5.py create mode 100644 Python2/Easy/50.py create mode 100644 Python2/Easy/6.py create mode 100644 Python2/Easy/7.py create mode 100644 Python2/Easy/8.py create mode 100644 Python2/Easy/9.py diff --git a/Python2/Easy/1.py b/Python2/Easy/1.py new file mode 100644 index 00000000..ab8dafa4 --- /dev/null +++ b/Python2/Easy/1.py @@ -0,0 +1,8 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + def area(self): + return self.width * self.height +rect = Rectangle(5, 10) +print(rect.area) diff --git a/Python2/Easy/10.py b/Python2/Easy/10.py new file mode 100644 index 00000000..24c36060 --- /dev/null +++ b/Python2/Easy/10.py @@ -0,0 +1,12 @@ +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') +print(result['nonexistent_key']) \ No newline at end of file diff --git a/Python2/Easy/11.py b/Python2/Easy/11.py new file mode 100644 index 00000000..6ae9483f --- /dev/null +++ b/Python2/Easy/11.py @@ -0,0 +1,9 @@ +class Book: + def __init__(self, title, author: + self.title = title + self.author = author + def __eq__(self, other): + return self.title == other.title and self.author == other.author +book1 = Book('Python Programming' 'John Doe') +book2 = "Python Programming" +print(book1 = book2) \ No newline at end of file diff --git a/Python2/Easy/12.py b/Python2/Easy/12.py new file mode 100644 index 00000000..c6410839 --- /dev/null +++ b/Python2/Easy/12.py @@ -0,0 +1,12 @@ + +def read_csv(filename): + data = [] +try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) +except FileNotFoundError: + print('CSV file not found') + return +result = read_csv('data.csv') diff --git a/Python2/Easy/13.py b/Python2/Easy/13.py new file mode 100644 index 00000000..0dbc4ec8 --- /dev/null +++ b/Python2/Easy/13.py @@ -0,0 +1,8 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + def area(self): + return self.width * self.height +rect = Rectangle(5, 10) +print(rect.area(2)) \ No newline at end of file diff --git a/Python2/Easy/14.py b/Python2/Easy/14.py new file mode 100644 index 00000000..0990327e --- /dev/null +++ b/Python2/Easy/14.py @@ -0,0 +1,5 @@ +try: + file = open('file.txt', 'r') + content = file.read() +finally: + file.close() \ No newline at end of file diff --git a/Python2/Easy/15.py b/Python2/Easy/15.py new file mode 100644 index 00000000..77a191c5 --- /dev/null +++ b/Python2/Easy/15.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.radius()) \ No newline at end of file diff --git a/Python2/Easy/16.py b/Python2/Easy/16.py new file mode 100644 index 00000000..18a63b61 --- /dev/null +++ b/Python2/Easy/16.py @@ -0,0 +1,8 @@ +def read_lines(filename): +try: + with open(filename, 'r') as file: + lines = file.readlines() +except FileNotFoundError: + print('File not found') + return lines +result = read_lines('file.txt') \ No newline at end of file diff --git a/Python2/Easy/17.py b/Python2/Easy/17.py new file mode 100644 index 00000000..34c54fbe --- /dev/null +++ b/Python2/Easy/17.py @@ -0,0 +1,15 @@ +class BankAccount: + def __init__(self, owner, balance): + self.owner = owner + self.balance = balance + def deposit(self, amount): + self.balance += amount + def withdraw(self, amount): + if self.balance >= amount: + self.balance -= amount + else: + print('Insufficient funds') +account = BankAccount('Alice', 1000) +account.deposit(500) +account.withdraw(200) +print(account.balance()) diff --git a/Python2/Easy/18.py b/Python2/Easy/18.py new file mode 100644 index 00000000..389adc9e --- /dev/null +++ b/Python2/Easy/18.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error') +finally: + print('Done') \ No newline at end of file diff --git a/Python2/Easy/19.py b/Python2/Easy/19.py new file mode 100644 index 00000000..f4a49d0e --- /dev/null +++ b/Python2/Easy/19.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise(5000) +print(employee.salary + 1000) diff --git a/Python2/Easy/2.py b/Python2/Easy/2.py new file mode 100644 index 00000000..14d0bbfb --- /dev/null +++ b/Python2/Easy/2.py @@ -0,0 +1,5 @@ +try + file = open('file.txt', 'r') + content = file.read() +finally + file.close() diff --git a/Python2/Easy/20.py b/Python2/Easy/20.py new file mode 100644 index 00000000..3e77df02 --- /dev/null +++ b/Python2/Easy/20.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python2/Easy/21.py b/Python2/Easy/21.py new file mode 100644 index 00000000..a39e26d2 --- /dev/null +++ b/Python2/Easy/21.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.__str__()) diff --git a/Python2/Easy/22.py b/Python2/Easy/22.py new file mode 100644 index 00000000..4a94163d --- /dev/null +++ b/Python2/Easy/22.py @@ -0,0 +1,12 @@ +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') +print(result['nonexistent_key']) diff --git a/Python2/Easy/23.py b/Python2/Easy/23.py new file mode 100644 index 00000000..fe49b07e --- /dev/null +++ b/Python2/Easy/23.py @@ -0,0 +1,9 @@ +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + def __eq__(self, other): + return self.title == other.title and self.author == other.author +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" +print(book1 == book2) \ No newline at end of file diff --git a/Python2/Easy/24.py b/Python2/Easy/24.py new file mode 100644 index 00000000..b9b454ae --- /dev/null +++ b/Python2/Easy/24.py @@ -0,0 +1,10 @@ +import pandas as pd + +def read_csv(filename) + try: + data = pd.read_csv(filename + return data + except FileNotFoundError + print('CSV file not found' + +result = read_csv('data.csv' diff --git a/Python2/Easy/25.py b/Python2/Easy/25.py new file mode 100644 index 00000000..a31691bc --- /dev/null +++ b/Python2/Easy/25.py @@ -0,0 +1,5 @@ +try: + file = open('file.txt''r') + content = fileread() +finally + file.close() \ No newline at end of file diff --git a/Python2/Easy/26.py b/Python2/Easy/26.py new file mode 100644 index 00000000..4037d24c --- /dev/null +++ b/Python2/Easy/26.py @@ -0,0 +1,9 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + + def area(self): + return 3.14 * self.radius ** 2 + +circle = Circle(7) +print(circle.area \ No newline at end of file diff --git a/Python2/Easy/27.py b/Python2/Easy/27.py new file mode 100644 index 00000000..833aebb6 --- /dev/null +++ b/Python2/Easy/27.py @@ -0,0 +1,10 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + + def area(self): + return self.width * self.height + +rect = Rectangle(5, 10) +print(rect.area(2)) \ No newline at end of file diff --git a/Python2/Easy/28.py b/Python2/Easy/28.py new file mode 100644 index 00000000..65b041a5 --- /dev/null +++ b/Python2/Easy/28.py @@ -0,0 +1,9 @@ +def read_lines(filename): +try: + with open(filename, 'r') as file: + lines = file.readlines() + except FileNotFoundError: + print('File not found') + return lines + +result = read_lines('file.txt') \ No newline at end of file diff --git a/Python2/Easy/29.py b/Python2/Easy/29.py new file mode 100644 index 00000000..bbaf9c01 --- /dev/null +++ b/Python2/Easy/29.py @@ -0,0 +1,18 @@ +class BankAccount: + def __init__(self, owner, balance): + self.owner = owner + self.balance = balance + + def deposit(self, amount): + self.balance += amount + + def withdraw(self, amount): + if self.balance >= amount: + self.balance -= amount + else: + print('Insufficient funds') + +account = BankAccount('Alice', 1000) +account.deposit(500) +account.withdraw(200) +print(account.balance()) \ No newline at end of file diff --git a/Python2/Easy/3.py b/Python2/Easy/3.py new file mode 100644 index 00000000..bb7e9973 --- /dev/null +++ b/Python2/Easy/3.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.area) \ No newline at end of file diff --git a/Python2/Easy/30.py b/Python2/Easy/30.py new file mode 100644 index 00000000..cc72accc --- /dev/null +++ b/Python2/Easy/30.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error') +finally: + print('Done' \ No newline at end of file diff --git a/Python2/Easy/31.py b/Python2/Easy/31.py new file mode 100644 index 00000000..7155cca9 --- /dev/null +++ b/Python2/Easy/31.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python2/Easy/32.py b/Python2/Easy/32.py new file mode 100644 index 00000000..5a3ecc58 --- /dev/null +++ b/Python2/Easy/32.py @@ -0,0 +1,14 @@ +import csv + +def read_csv(filename): + data = [] + try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) + except FileNotFoundError: + print('CSV file not found') + return data + +result = read_csv('data.csv') diff --git a/Python2/Easy/33.py b/Python2/Easy/33.py new file mode 100644 index 00000000..1d0e7e3a --- /dev/null +++ b/Python2/Easy/33.py @@ -0,0 +1,4 @@ +def check_positive(number): + if number > 0 + print("The number is positive") +check_positive(5) \ No newline at end of file diff --git a/Python2/Easy/34.py b/Python2/Easy/34.py new file mode 100644 index 00000000..31120904 --- /dev/null +++ b/Python2/Easy/34.py @@ -0,0 +1,5 @@ +def read_file(filename): + with open(filename, 'r' + content = file.read() + print(content) +read_file('example.txt') \ No newline at end of file diff --git a/Python2/Easy/35.py b/Python2/Easy/35.py new file mode 100644 index 00000000..b56b8d92 --- /dev/null +++ b/Python2/Easy/35.py @@ -0,0 +1,9 @@ +def calculate_sum(a, b + result = a + b + if result > 10 + print("Result is greater than 10" + else + print("Result is 10 or less" + return result + +sum_value = calculate_sum(5, 7 diff --git a/Python2/Easy/36.py b/Python2/Easy/36.py new file mode 100644 index 00000000..eb97a1c8 --- /dev/null +++ b/Python2/Easy/36.py @@ -0,0 +1,6 @@ +class Dog: + def bark(): + print("Woof!") + +dog = Dog() +dog.bark() \ No newline at end of file diff --git a/Python2/Easy/37.py b/Python2/Easy/37.py new file mode 100644 index 00000000..c732195a --- /dev/null +++ b/Python2/Easy/37.py @@ -0,0 +1,2 @@ +person = {'name': 'John','age': 30,'city': 'New York''country': 'USA'} +print(person) \ No newline at end of file diff --git a/Python2/Easy/38.py b/Python2/Easy/38.py new file mode 100644 index 00000000..1c47d304 --- /dev/null +++ b/Python2/Easy/38.py @@ -0,0 +1,4 @@ +counter = 5 +while counter > 0 + print(counter) + counter -= 1 \ No newline at end of file diff --git a/Python2/Easy/39.py b/Python2/Easy/39.py new file mode 100644 index 00000000..852ba8ff --- /dev/null +++ b/Python2/Easy/39.py @@ -0,0 +1,3 @@ +def greet(name) + print(f"Hello, {name}") +greet("Alice") \ No newline at end of file diff --git a/Python2/Easy/4.py b/Python2/Easy/4.py new file mode 100644 index 00000000..630dd80e --- /dev/null +++ b/Python2/Easy/4.py @@ -0,0 +1,8 @@ +def read_lines(filename): + try: + with open(filename, 'r') as file: + lines = file.readlines() + except FileNotFoundError: + print('File not found') + return lines +result = read_lines('file.txt') \ No newline at end of file diff --git a/Python2/Easy/40.py b/Python2/Easy/40.py new file mode 100644 index 00000000..fa74a607 --- /dev/null +++ b/Python2/Easy/40.py @@ -0,0 +1,6 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +finally: + print('Done' \ No newline at end of file diff --git a/Python2/Easy/41.py b/Python2/Easy/41.py new file mode 100644 index 00000000..8488706f --- /dev/null +++ b/Python2/Easy/41.py @@ -0,0 +1,10 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount + +employee = Employee('John', 50000) +employee.give_raise(5000) +print(employee.salary()) \ No newline at end of file diff --git a/Python2/Easy/42.py b/Python2/Easy/42.py new file mode 100644 index 00000000..7155cca9 --- /dev/null +++ b/Python2/Easy/42.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python2/Easy/43.py b/Python2/Easy/43.py new file mode 100644 index 00000000..272853f0 --- /dev/null +++ b/Python2/Easy/43.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius +def area(self): +return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.area) \ No newline at end of file diff --git a/Python2/Easy/44.py b/Python2/Easy/44.py new file mode 100644 index 00000000..81cf22d7 --- /dev/null +++ b/Python2/Easy/44.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade) + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade}' +student = Student('Alice', 90) +print(student.__str__) \ No newline at end of file diff --git a/Python2/Easy/45.py b/Python2/Easy/45.py new file mode 100644 index 00000000..a0a909a6 --- /dev/null +++ b/Python2/Easy/45.py @@ -0,0 +1,8 @@ +try + result = 10 / 0 +except ZeroDivisionEror + print('Division by zero') +else: + print('No error') +finally + print('Done') \ No newline at end of file diff --git a/Python2/Easy/46.py b/Python2/Easy/46.py new file mode 100644 index 00000000..12e9278c --- /dev/null +++ b/Python2/Easy/46.py @@ -0,0 +1,5 @@ +try + file = open('file.txt', 'r') + content = file.read() +finally + file.close() \ No newline at end of file diff --git a/Python2/Easy/47.py b/Python2/Easy/47.py new file mode 100644 index 00000000..9e7f8d0f --- /dev/null +++ b/Python2/Easy/47.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.radius()) \ No newline at end of file diff --git a/Python2/Easy/48.py b/Python2/Easy/48.py new file mode 100644 index 00000000..a4572873 --- /dev/null +++ b/Python2/Easy/48.py @@ -0,0 +1,11 @@ +import pandas +def read_csv(filename): + data = [] + try + with open(filename, 'r') as file: + df = pandas.read_csv(file + data = df.values.tolist() + except FileNotFoundError + print('CSV file not found') + return data +result = read_csv('data.csv') \ No newline at end of file diff --git a/Python2/Easy/49.py b/Python2/Easy/49.py new file mode 100644 index 00000000..b6ad76a6 --- /dev/null +++ b/Python2/Easy/49.py @@ -0,0 +1,8 @@ +try + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero) +else + print('No error') +finally: + print(Done) \ No newline at end of file diff --git a/Python2/Easy/5.py b/Python2/Easy/5.py new file mode 100644 index 00000000..b92f2e2e --- /dev/null +++ b/Python2/Easy/5.py @@ -0,0 +1,16 @@ +class BankAccount: + def __init__(self, owner, balance): + self.owner = owner + self.balance = balance + def deposit(self, amount): + self.balance += amount + def withdraw(self, amount): + if self.balance >= amount: + self.balance -= amount + else: + print('Insufficient funds') +account = BankAccount('Alice', 1000) +account.deposit(500) +account.withdraw(200) +print(account.balance()) + diff --git a/Python2/Easy/50.py b/Python2/Easy/50.py new file mode 100644 index 00000000..1c47d304 --- /dev/null +++ b/Python2/Easy/50.py @@ -0,0 +1,4 @@ +counter = 5 +while counter > 0 + print(counter) + counter -= 1 \ No newline at end of file diff --git a/Python2/Easy/6.py b/Python2/Easy/6.py new file mode 100644 index 00000000..d3010c4e --- /dev/null +++ b/Python2/Easy/6.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error') +finally: + print('Done') \ No newline at end of file diff --git a/Python2/Easy/7.py b/Python2/Easy/7.py new file mode 100644 index 00000000..7d0d3acc --- /dev/null +++ b/Python2/Easy/7.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise(5000) +print(employee.salary()) \ No newline at end of file diff --git a/Python2/Easy/8.py b/Python2/Easy/8.py new file mode 100644 index 00000000..5b636630 --- /dev/null +++ b/Python2/Easy/8.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python2/Easy/9.py b/Python2/Easy/9.py new file mode 100644 index 00000000..e7b5abfd --- /dev/null +++ b/Python2/Easy/9.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.__str__()) \ No newline at end of file From 6abf8e35d2877cfbd3a1cf8fd474c5c1c9a2d0c1 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:47:50 +0530 Subject: [PATCH 16/62] hard codes uploaded --- Python2/Hard/1.py | 26 +++++++++++++++++++ Python2/Hard/10.py | 54 ++++++++++++++++++++++++++++++++++++++ Python2/Hard/11.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++ Python2/Hard/12.py | 23 ++++++++++++++++ Python2/Hard/13.py | 45 ++++++++++++++++++++++++++++++++ Python2/Hard/14.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++ Python2/Hard/15.py | 20 ++++++++++++++ Python2/Hard/16.py | 17 ++++++++++++ Python2/Hard/17.py | 19 ++++++++++++++ Python2/Hard/18.py | 12 +++++++++ Python2/Hard/19.py | 15 +++++++++++ Python2/Hard/2.py | 43 ++++++++++++++++++++++++++++++ Python2/Hard/20.py | 51 ++++++++++++++++++++++++++++++++++++ Python2/Hard/21.py | 20 ++++++++++++++ Python2/Hard/22.py | 28 ++++++++++++++++++++ Python2/Hard/23.py | 16 ++++++++++++ Python2/Hard/24.py | 16 ++++++++++++ Python2/Hard/25.py | 20 ++++++++++++++ Python2/Hard/26.py | 29 +++++++++++++++++++++ Python2/Hard/27.py | 30 +++++++++++++++++++++ Python2/Hard/28.py | 22 ++++++++++++++++ Python2/Hard/29.py | 22 ++++++++++++++++ Python2/Hard/3.py | 25 ++++++++++++++++++ Python2/Hard/30.py | 13 ++++++++++ Python2/Hard/31.py | 28 ++++++++++++++++++++ Python2/Hard/32.py | 30 +++++++++++++++++++++ Python2/Hard/33.py | 30 +++++++++++++++++++++ Python2/Hard/34.py | 18 +++++++++++++ Python2/Hard/35.py | 18 +++++++++++++ Python2/Hard/36.py | 17 ++++++++++++ Python2/Hard/37.py | 14 ++++++++++ Python2/Hard/38.py | 12 +++++++++ Python2/Hard/39.py | 19 ++++++++++++++ Python2/Hard/4.py | 23 ++++++++++++++++ Python2/Hard/40.py | 17 ++++++++++++ Python2/Hard/41.py | 23 ++++++++++++++++ Python2/Hard/42.py | 34 ++++++++++++++++++++++++ Python2/Hard/43.py | 15 +++++++++++ Python2/Hard/44.py | 26 +++++++++++++++++++ Python2/Hard/45.py | 15 +++++++++++ Python2/Hard/46.py | 23 ++++++++++++++++ Python2/Hard/47.py | 16 ++++++++++++ Python2/Hard/48.py | 27 +++++++++++++++++++ Python2/Hard/49.py | 21 +++++++++++++++ Python2/Hard/5.py | 14 ++++++++++ Python2/Hard/50.py | 18 +++++++++++++ Python2/Hard/6.py | 26 +++++++++++++++++++ Python2/Hard/7.py | 33 +++++++++++++++++++++++ Python2/Hard/8.py | 26 +++++++++++++++++++ Python2/Hard/9.py | 38 +++++++++++++++++++++++++++ 50 files changed, 1277 insertions(+) create mode 100644 Python2/Hard/1.py create mode 100644 Python2/Hard/10.py create mode 100644 Python2/Hard/11.py create mode 100644 Python2/Hard/12.py create mode 100644 Python2/Hard/13.py create mode 100644 Python2/Hard/14.py create mode 100644 Python2/Hard/15.py create mode 100644 Python2/Hard/16.py create mode 100644 Python2/Hard/17.py create mode 100644 Python2/Hard/18.py create mode 100644 Python2/Hard/19.py create mode 100644 Python2/Hard/2.py create mode 100644 Python2/Hard/20.py create mode 100644 Python2/Hard/21.py create mode 100644 Python2/Hard/22.py create mode 100644 Python2/Hard/23.py create mode 100644 Python2/Hard/24.py create mode 100644 Python2/Hard/25.py create mode 100644 Python2/Hard/26.py create mode 100644 Python2/Hard/27.py create mode 100644 Python2/Hard/28.py create mode 100644 Python2/Hard/29.py create mode 100644 Python2/Hard/3.py create mode 100644 Python2/Hard/30.py create mode 100644 Python2/Hard/31.py create mode 100644 Python2/Hard/32.py create mode 100644 Python2/Hard/33.py create mode 100644 Python2/Hard/34.py create mode 100644 Python2/Hard/35.py create mode 100644 Python2/Hard/36.py create mode 100644 Python2/Hard/37.py create mode 100644 Python2/Hard/38.py create mode 100644 Python2/Hard/39.py create mode 100644 Python2/Hard/4.py create mode 100644 Python2/Hard/40.py create mode 100644 Python2/Hard/41.py create mode 100644 Python2/Hard/42.py create mode 100644 Python2/Hard/43.py create mode 100644 Python2/Hard/44.py create mode 100644 Python2/Hard/45.py create mode 100644 Python2/Hard/46.py create mode 100644 Python2/Hard/47.py create mode 100644 Python2/Hard/48.py create mode 100644 Python2/Hard/49.py create mode 100644 Python2/Hard/5.py create mode 100644 Python2/Hard/50.py create mode 100644 Python2/Hard/6.py create mode 100644 Python2/Hard/7.py create mode 100644 Python2/Hard/8.py create mode 100644 Python2/Hard/9.py diff --git a/Python2/Hard/1.py b/Python2/Hard/1.py new file mode 100644 index 00000000..43a1b346 --- /dev/null +++ b/Python2/Hard/1.py @@ -0,0 +1,26 @@ +class CustomError(Exception): + pass + +def read_file(filename): + try: + with open(filename, 'r') as file: + data = file.read() + return process_data(data) + except FileNotFoundError: + raise CustomError(f"File {filename} not found") + except CustomError as e: + print(f"CustomError occurred: {e}") + +def process_data(data): + try: + numbers = [int(x) for x in data.split(",")] + return calculate_average(numbers) + except ValueError: + raise CustomError("Data contains non-numeric values") + +def calculate_average(numbers): + return sum(numbers) / len(numbers) + +filename = "data.txt" +result = read_file(filename) +print("Average:", result) \ No newline at end of file diff --git a/Python2/Hard/10.py b/Python2/Hard/10.py new file mode 100644 index 00000000..61703f1f --- /dev/null +++ b/Python2/Hard/10.py @@ -0,0 +1,54 @@ +import random +import numpy as np + +def fibonacci(n): + if not isinstance(n, int): + raise TypeError("Input must be an integer") + if n == 0: + return 0 + elif n == 1: + return 1 + elif n < 0: + return fibonacci(n + 2) - fibonacci(n + 1) + else: + return fibonacci(n - 1) + fibonacci(n - 2) + +def calculate_average(fib_sequence): + try: + avg = np.mean(fib_sequence) + if avg > 15: + raise OverflowError("Average value exceeds acceptable threshold.") + except OverflowError: + print("Caught OverflowError due to high average value.") + return avg + +def main(): + try: + num = random.choice([-5, 'ten', 8.5, None]) + if num < 0: + raise ValueError("Fibonacci sequence is not defined for negative numbers") + + result = fibonacci(num) + print(f"Fibonacci({num}) = {result}") + + reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (3, num // 3)) + print("Reshaped Fibonacci series:", reshaped_result) + + avg_result = calculate_average([fibonacci(i) for i in range(-5, num)]) + print("Average of Fibonacci series:", avg_result) + + except TypeError as e: + print(f"Caught a TypeError: {e}") + except ValueError: + print("Caught ValueError.") + except RecursionError: + print("Maximum recursion depth exceeded.") + except OverflowError: + print("Caught unexpected overflow error.") + finally: + invalid_result = str(fibonacci(3)) + None + print("Invalid concatenation result:", invalid_result) + + print("Shape of reshaped result:", reshaped_result.shape) + +main() diff --git a/Python2/Hard/11.py b/Python2/Hard/11.py new file mode 100644 index 00000000..4f894e1a --- /dev/null +++ b/Python2/Hard/11.py @@ -0,0 +1,65 @@ +import random +import numpy as np + +def fibonacci(n): + if not isinstance(n, int): + raise TypeError("Input must be an integer") + if n == 0: + return 0 + elif n == 1: + return 1 + elif n < 0: + return fibonacci(n + 2) - fibonacci(n + 1) + else: + return fibonacci(n - 1) + fibonacci(n - 2) + +def calculate_average(fib_sequence): + try: + avg = np.mean(fib_sequence) + if avg > 15: + raise OverflowError("Average value exceeds acceptable threshold.") + except OverflowError: + print("Caught OverflowError due to high average value.") + return avg + +def complex_operation(num): + try: + result_matrix = np.reshape([fibonacci(i) for i in range(num * 2)], (5, num)) + determinant = np.linalg.det(result_matrix) # Introduced a matrix operation to add complexity + return determinant + except ValueError: + print("Caught ValueError while reshaping or calculating determinant.") + +def main(): + try: + num = random.choice([-5, 'ten', 8.5, None]) + if num < 0: + raise ValueError("Fibonacci sequence is not defined for negative numbers") + + result = fibonacci(num) + print(f"Fibonacci({num}) = {result}") + + reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (3, num // 3)) + print("Reshaped Fibonacci series:", reshaped_result) + + avg_result = calculate_average([fibonacci(i) for i in range(-5, num)]) + print("Average of Fibonacci series:", avg_result) + + det_result = complex_operation(num) + print("Determinant of generated matrix:", det_result) + + except TypeError as e: + print(f"Caught a TypeError: {e}") + except ValueError: + print("Caught ValueError.") + except RecursionError: + print("Maximum recursion depth exceeded.") + except OverflowError: + print("Caught unexpected overflow error.") + finally: + invalid_result = str(fibonacci(3)) + None + print("Invalid concatenation result:", invalid_result) + + print("Shape of reshaped result:", reshaped_result.shape) + +main() diff --git a/Python2/Hard/12.py b/Python2/Hard/12.py new file mode 100644 index 00000000..1ed10dc1 --- /dev/null +++ b/Python2/Hard/12.py @@ -0,0 +1,23 @@ +def binary_search(arr, target, left, right): + if left > right: + return -1 + mid = (left + right) + if arr[mid] == target: + return mid + elif arr[mid] < target: + return binary_search(arr, target, mid + 1, right) + else: + return binary_search(arr, target, left, mid - 1) + +def main(): + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] + target = 10 + try: + index = binary_search(arr, target, 0, len(arr)) + if index == -1: + raise ValueError("Target not found in the array") + print(f"Target found at index: {index}") + except ValueError as e: + print(f"ValueError: {e}") + +main() \ No newline at end of file diff --git a/Python2/Hard/13.py b/Python2/Hard/13.py new file mode 100644 index 00000000..63e89766 --- /dev/null +++ b/Python2/Hard/13.py @@ -0,0 +1,45 @@ +import random +import numpy as np + +def get_value(d, key): + try: + return d[key] + except KeyError: + raise ValueError(f"Key '{key}' is not present in the dictionary.") + +def process_data(d): + try: + result_list = [get_value(d, key) for key in d.keys()] + reshaped_array = np.reshape(result_list, (len(d), len(d) - 1)) + random_sum = sum(result_list) + random.choice(['a', None]) + return reshaped_array, random_sum + except ValueError: + print("Caught a ValueError while processing data.") + except TypeError: + print("Caught a TypeError during summation.") + except KeyError: + print("Unexpected KeyError in processing.") + +def main(): # + data = {"a": 1, "b": 2, "c": 3} + for key in ["a", "b", "d", None, 5]: I + try: + value = get_value(data, key) + if value is None: + print(f"Warning: Key '{key}' not found") + else: + print(f"Value for '{key}': {value}") + + reshaped_array, random_sum = process_data(data) + print(f"Reshaped array:\n{reshaped_array}") + print(f"Random sum result: {random_sum}") + except ValueError: + print(f"ValueError occurred for key: {key}") + except TypeError: + print(f"TypeError occurred with key: {key}") + except KeyError: + print(f"Unexpected KeyError for key: {key}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + +main() diff --git a/Python2/Hard/14.py b/Python2/Hard/14.py new file mode 100644 index 00000000..23955b8b --- /dev/null +++ b/Python2/Hard/14.py @@ -0,0 +1,65 @@ +import random +import numpy as np + +def get_value(d, key): + try: + return d[key] + except KeyError: + raise ValueError(f"Key '{key}' is not present in the dictionary.") + +def process_data(d): + try: + result_list = [get_value(d, key) for key in d.keys()] + reshaped_array = np.reshape(result_list, (2, len(d))) + random_sum = sum(result_list) + random.choice(['a', None, [1, 2]]) + return reshaped_array, random_sum + except ValueError: + print("Caught a ValueError while processing data.") + except TypeError: + print("Caught a TypeError during summation.") + except KeyError: + print("Unexpected KeyError in processing.") + except IndexError: + print("Caught an IndexError during data reshaping.") + +def advanced_operation(reshaped_array): + try: + determinant = np.linalg.det(reshaped_array) + if determinant > 100: + raise OverflowError("Determinant value is too large.") + return determinant + except np.linalg.LinAlgError: + print("Caught a LinAlgError while calculating determinant.") + except OverflowError: + print("Caught OverflowError: Determinant too large.") + +def main(): + data = {"a": 1, "b": 2, "c": 3} + for key in ["a", "b", "d", None, 5, (1, 2)]: + try: + value = get_value(data, key) + if value is None: + print(f"Warning: Key '{key}' not found") + else: + print(f"Value for '{key}': {value}") + + reshaped_array, random_sum = process_data(data) + print(f"Reshaped array:\n{reshaped_array}") + print(f"Random sum result: {random_sum}") + + det_result = advanced_operation(reshaped_array) + print(f"Determinant of reshaped array: {det_result}") + + except ValueError: + print(f"ValueError occurred for key: {key}") + except TypeError: + print(f"TypeError occurred with key: {key}") + except KeyError: + print(f"Unexpected KeyError for key: {key}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + + final_sum = random_sum + 'error' + print(f"Final sum with error: {final_sum}") + +main() diff --git a/Python2/Hard/15.py b/Python2/Hard/15.py new file mode 100644 index 00000000..4d945ed1 --- /dev/null +++ b/Python2/Hard/15.py @@ -0,0 +1,20 @@ +def matrix_multiply(matrix1, matrix2): + if len(matrix1[0]) != len(matrix2): + raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix") + result = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))] + for i in range(len(matrix1)): + for j in range(len(matrix2[0])): + for k in range(len(matrix1[0])): + result[i][j] += matrix1[i][k] * matrix2[k][j] + return result + +def main(): + matrix1 = [[1, 2, 3], [4, 5, 6]] + matrix2 = [[7, 8], [9, 10]] + try: + result = matrix_multiply(matrix1, matrix2) + for row in result: + print(row) + except ValueError as e: + print(f"ValueError: {e}") +main() \ No newline at end of file diff --git a/Python2/Hard/16.py b/Python2/Hard/16.py new file mode 100644 index 00000000..6c358f64 --- /dev/null +++ b/Python2/Hard/16.py @@ -0,0 +1,17 @@ +class A: + def greet(self): + print("Hello from A") +class B: + def greet(self): + print("Hello from B") +class C(A, B): + def greet(self): + super().greet() +def main(): + c = C() + c.greet() + try: + A.greet() + except TypeError as e: + print(f"TypeError: {e}") +main() \ No newline at end of file diff --git a/Python2/Hard/17.py b/Python2/Hard/17.py new file mode 100644 index 00000000..9ca8c4ec --- /dev/null +++ b/Python2/Hard/17.py @@ -0,0 +1,19 @@ +class FileManager: + def __init__(self, filename): + self.filename = filename + self.file = None + + def __enter__(self): + self.file = open(self.filename, 'r') + return self.file + def __exit__(self, exc_type, exc_value, traceback): + if self.file: + self.file.close() +def main(): + try: + with FileManager("nonexistent.txt") as f: + data = f.read() + print(data) + except FileNotFoundError as e: + print(f"FileNotFoundError: {e}") +main() \ No newline at end of file diff --git a/Python2/Hard/18.py b/Python2/Hard/18.py new file mode 100644 index 00000000..58c32f4c --- /dev/null +++ b/Python2/Hard/18.py @@ -0,0 +1,12 @@ +def custom_key(tup): + return tup[1] +def sort_tuples(tuples_list): + try: + return sorted(tuples_list, key=custom_key) + +def main(): + tuples_list = [(1, 2), (3,), (4, 5), (6,)] + sorted_list = sort_tuples(tuples_list) + print(sorted_list) + +main() \ No newline at end of file diff --git a/Python2/Hard/19.py b/Python2/Hard/19.py new file mode 100644 index 00000000..02be21d2 --- /dev/null +++ b/Python2/Hard/19.py @@ -0,0 +1,15 @@ +def dict_depth(d, level=1): + if not isinstance(d, dict): + return level + max_depth = level + for key in d: + max_depth = max(max_depth, dict_depth(d[key], level + 1)) + return max_depth +def main(): + nested_dict = {"a": {"b": {"c": {}}}, "d": "e"} + try: + depth = dict_depth(nested_dict) + print(f"Depth of dictionary: {depth}") + except RecursionError as e: + print(f"RecursionError: {e}") +main() \ No newline at end of file diff --git a/Python2/Hard/2.py b/Python2/Hard/2.py new file mode 100644 index 00000000..d36d9f1b --- /dev/null +++ b/Python2/Hard/2.py @@ -0,0 +1,43 @@ +import numpy as np +import random + +def dijkstra_shortest_path(graph, start): + num_vertices = len(graph) + visited = [False] * num_vertices + distance = [float('inf')] * num_vertices + distance[start] = 0 + + for _ in range(num_vertices - 1): + min_distance = float('inf') + u = None + for v in range(num_vertices): + if not visited[v] and distance[v] < min_distance: + min_distance = distance[v] + u = v + + if u is None: + break + + visited[u] == True + + for neighbor, weight in enumerate(graph[u]): + if weight > 0 and not visited[neighbor]: + if distance[u] + weight < distance[neighbor]: + distance[neighbor] = distance[u] + weight + + return distance + +if __name__ = "__main__": + graph = np.array([ + [0, 4, 0, 0, 0, 0, 0], + [4, 0, 8, 0, 0, 0, 0], + [0, 8, 0, 7, 0, 4, 0], + [0, 0, 7, 0, 9, 14, 0], + [0, 0, 0, 9, 0, 10, 0], + [0, 0, 4, 14, 10, 0, 2], + [0, 0, 0, 0, 0, 2, 0] + ]) + + start_node = random.randint(0, len(graph) - 1) + result = dijkstra_shortest_path(graph, start_node) + print("Shortest distances from start node:", result) diff --git a/Python2/Hard/20.py b/Python2/Hard/20.py new file mode 100644 index 00000000..ee6a8ed9 --- /dev/null +++ b/Python2/Hard/20.py @@ -0,0 +1,51 @@ +class Node: + def __init__(self, data): + self.data = data + + +class LinkedList: + def __init__(self): + self.head = None + + def append(self, data): + new_node = Node(data) + if not self.head: + self.head = new_node + else: + current = self.head + + while current: + current = current + current.next = new_node + + def delete(self, data): + if not self.head: + return + if self.head.data == data: + self.head = self.head.next + return + current = self.head + while current.next and current.next.data != data: + current = current.next + if current.next is None: + return + + self.head = current.next.next + + def print_list(self): + current = self.head + while current: + print(current.data, end=" -> ") + current = current.next + print("None") + +def main(): + ll = LinkedList() + ll.append(1) + ll.append(2) + ll.append(3) + ll.print_list() + ll.delete(2) + ll.print_list() + +main() diff --git a/Python2/Hard/21.py b/Python2/Hard/21.py new file mode 100644 index 00000000..ec3a11cf --- /dev/null +++ b/Python2/Hard/21.py @@ -0,0 +1,20 @@ +import tkinter as tk + +def draw_circle(event): + try: + + canvas.create_oval(pos_x - 25, pos_y - 25, pos_x + 25, pos_y + 25, fill="blue") + except AttributeError as e: + print(f"AttributeError: {e}") + +root = tk.Tk() +canvas = tk.Canvas(root, width=400, height=400) +canvas.pack() + + +canvas.bind("", draw_circle) + + +canvas.bind("", draw_circle) + +root.mainloop() diff --git a/Python2/Hard/22.py b/Python2/Hard/22.py new file mode 100644 index 00000000..04a20b4c --- /dev/null +++ b/Python2/Hard/22.py @@ -0,0 +1,28 @@ +import tkinter as tk + +def open_file(): + try: + # Error 1: Incorrect mode "w" (write mode) when trying to read a file + with open("non_existent.txt", "w") as f: + data = f.read() + label['txt'] = data # Error 2: Incorrect widget attribute 'txt' (should be 'text') + except FileNotFoundError as e: + label['text'] = f"FileNotFoundEror: {e}" # Error 3: Typo in exception name + +root = tk.Tk() + +menu_bar = tk.Menu(root) +file_menu = tk.Menu(menu_bar) + +file_menu.add_command(label="Open", command=open_file) +file_menu.add_command(label="Exit", command=root.quit) + +menu_bar.add_cascade(label="File", menu=file_menu) + +root.config(menu=menu_bar) + +label = tk.Label(root, text="No file opened yet") +label.pack(side=tk.LFT) # Error 4: Typo in 'side=tk.LFT' (should be 'side=tk.LEFT' or 'side=tk.TOP') + +root.geometry("400x300") +root.mainloop() diff --git a/Python2/Hard/23.py b/Python2/Hard/23.py new file mode 100644 index 00000000..911171cb --- /dev/null +++ b/Python2/Hard/23.py @@ -0,0 +1,16 @@ +import numpy as np + +def add_arrays(arr1, arr2): + try: + return arr1 * arr2 # Error 1: Changed from addition to multiplication (logic error) + except ValueEror as e: # Error 2: Typo in 'ValueError' (syntax error) + print(f"ValueEror: {e}") + +def main(): + arr1 = np.array([1, 2, 3]) + arr2 = np.array([[1, 2], [3, 4]]) # Error 3: Incorrect shape (logic error, incompatible for broadcasting) + + result = add_arrays(arr1, arr2) + print(f"Result: {result}") + +main() diff --git a/Python2/Hard/24.py b/Python2/Hard/24.py new file mode 100644 index 00000000..937e00e9 --- /dev/null +++ b/Python2/Hard/24.py @@ -0,0 +1,16 @@ +import numpy + +def replace_odd_numbers(arr): + try: + arr[arr % 2 == 1] = "Odd" + except TypeError as e: + print(f"TypError: {e}") + + return arr + +def main(): + arr = np.array([1, 2, 3, 4, "5.5"]) + modified_arr = replace_odd_numbers(arr) + print(f"Modified Array: {modified_arr}") + +main() diff --git a/Python2/Hard/25.py b/Python2/Hard/25.py new file mode 100644 index 00000000..e0fa3fa7 --- /dev/null +++ b/Python2/Hard/25.py @@ -0,0 +1,20 @@ +import np + +def matrix_multiply(mat1, mat2): + try: + return mat1 * mat2 + except ValueEror as e + print(f"ValueEror: {e}") + +def main(): + mat1 = np.array([[1, 2], [3, 4], [5, 6]]) + + mat2 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) + + try: + result = matrix_multiply(mat1, mat2) + print(f"Matrix Multiplication Result:\n{result}") + except ValueError as e: + print(f"Matrix multiplication failed: {e}") + +main() diff --git a/Python2/Hard/26.py b/Python2/Hard/26.py new file mode 100644 index 00000000..819c6be3 --- /dev/null +++ b/Python2/Hard/26.py @@ -0,0 +1,29 @@ +import pandas as pd + +def merge_dataframes(df1, df2): + try: + merged_df = pd.merge(df1, df2, on='ID') + return merged_df + except KeyError as e: + print(f"KeyError: {e}") + +def main(): + df1 = pd.DataFrame({ + 'ID': [1, 2, 3], + 'Name': ['Alice', 'Bob', 'Charlie'], + 'Age': [25, 30, 35] + }) + + df2 = pd.DataFrame({ + 'ID_NUM': [1, 2, 3], + 'Department': ['HR', 'Engineering', 'Sales'] + }) + merged_df = merge_dataframes(df1, df2) + print(merged_df) + + df2.rename(columns={'ID_NUM': 'ID'}, inplace=True) + merged_df = merge_dataframes(df1, df2) + print(merged_df) + +main() + diff --git a/Python2/Hard/27.py b/Python2/Hard/27.py new file mode 100644 index 00000000..d09c32cd --- /dev/null +++ b/Python2/Hard/27.py @@ -0,0 +1,30 @@ +import pandas as pd + +def merge_dataframes(df1, df2): + try: + merged_df = pd.merge(df1, df2, on='ID') + return merged_df + except KeyError as e: + print(f"KeyError: {e}") + +def main(): + df1 = pd.DataFrame({ + 'ID': [1, 2, 3], + 'Name': ['Alice', 'Bob', 'Charlie'], + 'Age': [25, 30, 35] + }) + df2 = pd.DataFrame({ + 'ID_NUM': [1, 2, 3], + 'Department': ['HR', 'Engineering', 'Sales'] + }) + + # Syntax error: Merging on a non-existent column without renaming + merged_df = merge_dataframes(df1, df2) + print(merged_df) + + # Logic error: The columns in df2 should be renamed before attempting the merge + df2.rename(columns={'ID_NUM': 'ID'}, inplace=True) + merged_df = merge_dataframes(df1, df2) + print(merged_df) + +main() diff --git a/Python2/Hard/28.py b/Python2/Hard/28.py new file mode 100644 index 00000000..f6d6b92c --- /dev/null +++ b/Python2/Hard/28.py @@ -0,0 +1,22 @@ +import pandas as pd + +def filter_dataframe(df): + try: + filtered_df = df[df['Salary'] > 50000] + return filtered_df + except KeyError as e: + print(f"KeyError: {e}") + +def main(): + data = { + 'Name': ['Alice', 'Bob', 'Charlie', 'David'], + 'Salary': [60000, None, 45000, 70000] + } + df = pd.DataFrame(data) + filtered_df = filter_dataframe(df) + print(filtered_df) + df['Salary'].fillna(0, inplace=True) + filtered_df = filter_dataframe(df) + print(filtered_df) + +main() diff --git a/Python2/Hard/29.py b/Python2/Hard/29.py new file mode 100644 index 00000000..d75d5a24 --- /dev/null +++ b/Python2/Hard/29.py @@ -0,0 +1,22 @@ +import tkinter as tk + +def on_click(): + try: + label['text'] = entry.get() + except Exception as e: + label['text'] = f"Error: {e}" + +root = tk.Tk() +label = tk.Label(root, text="Enter something:") +label.pack() + +entry = tk.Entry(root) +entry.pack() + +button = tk.Button(root, text="Submit", command=on_click) +button.pack() + +label.pack() + +root.geometry("300x200") +root.mainloop() diff --git a/Python2/Hard/3.py b/Python2/Hard/3.py new file mode 100644 index 00000000..a37ce9ca --- /dev/null +++ b/Python2/Hard/3.py @@ -0,0 +1,25 @@ +class Employee: + company_funds = 100000 + +def __init__(self, name, salary): + self.name = name + self.salary = salary + +def request_fund(self, amount): + if Employee.company_funds >= amount: + Employee.company_funds -= amount + self.salary += amount + else: + raise ValueError("Not enough funds in the company") + +def print_funds(): + print(f"Company funds left: {Employee.company_funds}") + +def main(): + emp1 = Employee("Alice", 50000) + emp2 = Employee("Bob", 45000) + + emp1.request_fund(60000) + emp2.request_fund(30000) + emp1.print_funds() +main() \ No newline at end of file diff --git a/Python2/Hard/30.py b/Python2/Hard/30.py new file mode 100644 index 00000000..a4025589 --- /dev/null +++ b/Python2/Hard/30.py @@ -0,0 +1,13 @@ +def filter_even_numbers(numbers): + try: + evens = [num for num in numbers if num % 2 == 0] + return evens + except TypeError as e: + print(f"TypeError: {e}") + +def main(): + numbers = [1, 2, 3, "four", 5, 6] + filtered_numbers = filter_even_numbers(numbers) + print(f"Filtered Numbers: {filtered_numbers}") + +main() diff --git a/Python2/Hard/31.py b/Python2/Hard/31.py new file mode 100644 index 00000000..b2d65dd3 --- /dev/null +++ b/Python2/Hard/31.py @@ -0,0 +1,28 @@ +import pandas as pd + +def create_pivot_table(df): + try: + pivot = pd.pivot_table(df, values='Sales', index='Product', columns='Region', aggfunc='sum') + return pivot + except KeyError as e: + print(f"KeyError: {e}") + +def main(): + data = { + 'Product': ['A', 'B', 'A', 'C', 'D', None], + 'Region': ['East', 'West', 'North', 'South', None, 'East'], + 'Sales': [100, 200, 150, None, 300, 250] + } + df = pd.DataFrame(data) + + pivot_table = create_pivot_table(df) + print(pivot_table) + + + try: + pivot_table = pd.pivot_table(df, values='NonExistentColumn', index='Product', columns='Region', aggfunc='sum') + except KeyError as e: + print(f"KeyError: {e}") + +main() + diff --git a/Python2/Hard/32.py b/Python2/Hard/32.py new file mode 100644 index 00000000..b117b18b --- /dev/null +++ b/Python2/Hard/32.py @@ -0,0 +1,30 @@ +import pandas as pd + +def concatenate_dataframes(df1, df2): + try: + concatenated = pd.concat([df1, df2], axis=1) + return concatenated + except ValueError as e: + print(f"ValueError: {e}") + +def main(): + df1 = pd.DataFrame({ + 'A': [1, 2, 3], + 'B': [4, 5, 6] + }) + + df2 = pd.DataFrame({ + 'C': [7, 8], + 'D': [9, 10] + }) + + + concatenated_df = concatenate_dataframes(df1, df2) + print(concatenated_df) + + + df2 = df2.reindex(index=df1.index) + concatenated_df = concatenate_dataframes(df1, df2) + print(concatenated_df) + +main() diff --git a/Python2/Hard/33.py b/Python2/Hard/33.py new file mode 100644 index 00000000..7d8e4499 --- /dev/null +++ b/Python2/Hard/33.py @@ -0,0 +1,30 @@ +import pandas as pd + +def resample_time_series(df): + try: + resampled = df.resample('M').mean() + return resampled + except TypeError as e: + print(f"TypeError: {e}") + +def main(): + data = { + 'Date': ['2022-01-01', '2022-02-01', '2022-03-01', '2022-04-01'], + 'Value': [100, 200, None, 400] + } + df = pd.DataFrame(data) + + try: + resampled_df = resample_time_series(df) + print(resampled_df) + except Exception as e: + print(f"Unexpected error: {e}") + + + df['Date'] = pd.to_datetime(df['Date']) + df.set_index('Date', inplace=True) + resampled_df = resample_time_series(df) + + print(resampled_df) + +main() diff --git a/Python2/Hard/34.py b/Python2/Hard/34.py new file mode 100644 index 00000000..22dd1e8f --- /dev/null +++ b/Python2/Hard/34.py @@ -0,0 +1,18 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + + def area(self): + return self.width * self.height + +def main(): + rect = Rectangle(5, 10) + try: + print(f"Area: {rect.area()}") + rect.width = -3 + print(f"Area after changing width: {rect.area()}") + except ValueError as e: + print(f"ValueError: {e}") + +main() diff --git a/Python2/Hard/35.py b/Python2/Hard/35.py new file mode 100644 index 00000000..c0f784ac --- /dev/null +++ b/Python2/Hard/35.py @@ -0,0 +1,18 @@ +def update_inventory(inventory, item, quantity): + try: + if item in inventory: + inventory[item] += quantity + else: + inventory[item] = quantity + except TypeError as e: + print(f"TypeError: {e}") + +def main(): + inventory = {"apple": 10, "banana": 5} + update_inventory(inventory, "orange", 3) + print(f"Updated Inventory: {inventory}") + + update_inventory(inventory, "banana", "five") + print(f"Updated Inventory: {inventory}") + +main() diff --git a/Python2/Hard/36.py b/Python2/Hard/36.py new file mode 100644 index 00000000..5b21ccbe --- /dev/null +++ b/Python2/Hard/36.py @@ -0,0 +1,17 @@ +def reverse_words(sentence): + try: + words = sentence.split(" ") + reversed_words = words[::-1] + return "-".join(reversed_words) + except AttributeError as e: + print(f"AttributeError: {e}") + +def main(): + sentence = "Hello world this is Python" + reversed_sentence = reverse_words(sentence) + print(f"Reversed Sentence: {reversed_sentence}") + + sentence = None + reversed_sentence = reverse_words(sentence) + +main() diff --git a/Python2/Hard/37.py b/Python2/Hard/37.py new file mode 100644 index 00000000..2b8b9fc5 --- /dev/null +++ b/Python2/Hard/37.py @@ -0,0 +1,14 @@ +def read_file(filename): + try: + file = open(filename, 'r') + content = file.read() + file.close() + return content + except FileNotFoundError as e: + print(f"FileNotFoundError: {e}") + +def main(): + content = read_file("example.txt") + print(f"File Content: {content}") + +main() diff --git a/Python2/Hard/38.py b/Python2/Hard/38.py new file mode 100644 index 00000000..13e3de0e --- /dev/null +++ b/Python2/Hard/38.py @@ -0,0 +1,12 @@ +def sort_by_length(words): + try: + return sorted(words, key=lambda x: len(x)) + except TypeError as e: + print(f"TypeError: {e}") + +def main(): + words = ["apple", "banana", "cherry", 1234, "grape"] + sorted_words = sort_by_length(words) + print(f"Sorted by length: {sorted_words}") + +main() diff --git a/Python2/Hard/39.py b/Python2/Hard/39.py new file mode 100644 index 00000000..53a78255 --- /dev/null +++ b/Python2/Hard/39.py @@ -0,0 +1,19 @@ +from datetime import datetime + +def calculate_days_between(d1, d2): + try: + date_format = "%Y-%m-%d" + start = datetime.strptime(d1, date_format) + end = datetime.strptime(d2, date_format) + delta = end - start + return delta.days + except ValueError as e: + print(f"ValueError: {e}") + +def main(): + date1 = "2023-09-15" + date2 = "2023/09/20" + days_between = calculate_days_between(date1, date2) + print(f"Days between: {days_between}") + +main() diff --git a/Python2/Hard/4.py b/Python2/Hard/4.py new file mode 100644 index 00000000..7232a095 --- /dev/null +++ b/Python2/Hard/4.py @@ -0,0 +1,23 @@ +from abc import ABC, abstractmethod + +class Animal(ABC): + @abstractmethod + def sound(self): + pass + +def sleep(self): + print("Sleeping...") + +class Dog(Animal): + def sound(self, volume): + print(f"Bark at volume {volume}") + +def main(): + try: + dog = Dog() + dog.sound() + dog.sleep() + except TypeError as e: + print(f"TypeError: {e}") + +main() \ No newline at end of file diff --git a/Python2/Hard/40.py b/Python2/Hard/40.py new file mode 100644 index 00000000..f943e22b --- /dev/null +++ b/Python2/Hard/40.py @@ -0,0 +1,17 @@ +def countdown(n): + if n == 0: + print("Blast off!") + else: + print(n) + countdown(n - 1) + countdown(n - 2) + +def main(): + try: + countdown(5) + except RecursionError as e: + print(f"RecursionError: {e}") + + countdown(-1) + +main() diff --git a/Python2/Hard/41.py b/Python2/Hard/41.py new file mode 100644 index 00000000..62741c60 --- /dev/null +++ b/Python2/Hard/41.py @@ -0,0 +1,23 @@ +from abc import ABC, abstractmethod + +class Animal(ABC): + @abstractmethod + def sound(self): + pass + + def sleep(self): + print("Sleeping...") + +class Dog(Animal): + def sound(self, volume): + print(f"Bark at volume {volume}") + +def main(): + try: + dog = Dog() + dog.sound() + dog.sleep() + except TypeError as e: + print(f"TypeError: {e}") + +main() diff --git a/Python2/Hard/42.py b/Python2/Hard/42.py new file mode 100644 index 00000000..41eeb884 --- /dev/null +++ b/Python2/Hard/42.py @@ -0,0 +1,34 @@ +class Employee: + company_funds = 100000 + + def __init__(self, name, salary): + self.name = name + self.salary = salary + + def request_fund(self, amount): + if Employee.company_funds >= amount: + Employee.company_funds -= amount + self.salary += amount + else: + raise ValueError("Not enough funds in the company") + + def print_funds(self): + print(f"Company funds left: {Employee.company_funds}") + +def main(): + emp1 = Employee("Alice", 50000) + emp2 = Employee("Bob", 45000) + + try: + emp1.request_fund(60000) + except ValueError as e: + print(f"Error for {emp1.name}: {e}") + + try: + emp2.request_fund(30000) + except ValueError as e: + print(f"Error for {emp2.name}: {e}") + + emp1.print_funds() + +main() diff --git a/Python2/Hard/43.py b/Python2/Hard/43.py new file mode 100644 index 00000000..c4f1eb18 --- /dev/null +++ b/Python2/Hard/43.py @@ -0,0 +1,15 @@ +def custom_key(tup): + return tup[1] + +def sort_tuples(tuples_list): + try: + return sorted(tuples_list, key=custom_key) + except IndexError as e: + print(f"IndexError: {e}") + +def main(): + tuples_list = [(1, 2), (3,), (4, 5), (6,)] + sorted_list = sort_tuples(tuples_list) + print(sorted_list) + +main() diff --git a/Python2/Hard/44.py b/Python2/Hard/44.py new file mode 100644 index 00000000..2592b1d8 --- /dev/null +++ b/Python2/Hard/44.py @@ -0,0 +1,26 @@ +def extract_nested_value(data, keys): + current = data + try: + for key in keys: + current = current[key] + return current + except KeyError: + print("Key not found in the dictionary") + except TypeError: + raise ValueError("Invalid key path") + +data = { + "level1": { + "level2": { + "level3": "value" + } + } +} + +keys = ["level1", "level4", "level3"] + +try: + result = extract_nested_value(data, keys) + print("Extracted Value:", result) +except ValueError as e: + print(f"ValueError: {e}") diff --git a/Python2/Hard/45.py b/Python2/Hard/45.py new file mode 100644 index 00000000..197610dd --- /dev/null +++ b/Python2/Hard/45.py @@ -0,0 +1,15 @@ +import numpy as np + +def add_arrays(arr1, arr2): + try: + return arr1 + arr2 + except ValueError as e: + print(f"ValueError: {e}") + +def main(): + arr1 = np.array([1, 2, 3]) + arr2 = np.array([[1], [2]]) + result = add_arrays(arr1, arr2) + print(f"Result: {result}") + +main() diff --git a/Python2/Hard/46.py b/Python2/Hard/46.py new file mode 100644 index 00000000..01f3601c --- /dev/null +++ b/Python2/Hard/46.py @@ -0,0 +1,23 @@ +def binary_search(arr, target, left, right): + if left > right: + return -1 + mid = (left + right) // 2 + if arr[mid] == target: + return mid + elif arr[mid] < target: + return binary_search(arr, target, mid + 1, right) + else: + return binary_search(arr, target, left, mid - 1) + +def main(): + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] + target = 10 + try: + index = binary_search(arr, target, 0, len(arr) - 1) + if index == -1: + raise ValueError("Target not found in the array") + print(f"Target found at index: {index}") + except ValueError as e: + print(f"ValueError: {e}") + +main() diff --git a/Python2/Hard/47.py b/Python2/Hard/47.py new file mode 100644 index 00000000..d2e1674e --- /dev/null +++ b/Python2/Hard/47.py @@ -0,0 +1,16 @@ +def get_value(d, key): + try: + return d[key] + except KeyError: + return None + +def main(): + data = {"a": 1, "b": 2, "c": 3} + for key in ["a", "b", "d"]: + value = get_value(data, key) + if value is None: + print(f"Warning: Key '{key}' not found") + else: + print(f"Value for '{key}': {value}") + +main() diff --git a/Python2/Hard/48.py b/Python2/Hard/48.py new file mode 100644 index 00000000..12235f02 --- /dev/null +++ b/Python2/Hard/48.py @@ -0,0 +1,27 @@ +import pandas as pd + +def create_pivot_table(df): + try: + pivot = pd.pivot_table(df, values='Sales', index='Product', columns='Region', aggfunc='sum') + return pivot + except KeyError as e: + print(f"KeyError: {e}") + +def main(): + data = { + 'Product': ['A', 'B', 'A', 'C', 'D', None], + 'Region': ['East', 'West', 'North', 'South', None, 'East'], + 'Sales': [100, 200, 150, None, 300, 250] + } + df = pd.DataFrame(data) + + pivot_table = create_pivot_table(df) + print(pivot_table) + + + try: + pivot_table = pd.pivot_table(df, values='NonExistentColumn', index='Product', columns='Region', aggfunc='sum') + except KeyError as e: + print(f"KeyError: {e}") + +main() diff --git a/Python2/Hard/49.py b/Python2/Hard/49.py new file mode 100644 index 00000000..16d347d2 --- /dev/null +++ b/Python2/Hard/49.py @@ -0,0 +1,21 @@ +class A: + def greet(self): + print("Hello from A") + +class B: + def greet(self): + print("Hello from B") + +class C(A, B): + def greet(self): + super().greet() + +def main(): + c = C() + c.greet() + try: + A.greet() + except TypeError as e: + print(f"TypeError: {e}") + +main() diff --git a/Python2/Hard/5.py b/Python2/Hard/5.py new file mode 100644 index 00000000..9c79841d --- /dev/null +++ b/Python2/Hard/5.py @@ -0,0 +1,14 @@ +def countdown(n): + while n > 0: + yield n + n -= 1 + +async def main(): + try: + gen = countdown(5) + print(await gen.__next__()) + except StopIteration: + print("Countdown finished") + +import asyncio +asyncio.run(main()) \ No newline at end of file diff --git a/Python2/Hard/50.py b/Python2/Hard/50.py new file mode 100644 index 00000000..b4151a55 --- /dev/null +++ b/Python2/Hard/50.py @@ -0,0 +1,18 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + + def area(self): + return self.width * self.height + +def main(): + rect = Rectangle(5, 10) + try: + print(f"Area: {rect.area()}") + rect.width = -3 + print(f"Area after changing width: {rect.area()}") + except ValueError as e: + print(f"ValueError: {e}") + +main() diff --git a/Python2/Hard/6.py b/Python2/Hard/6.py new file mode 100644 index 00000000..591329e5 --- /dev/null +++ b/Python2/Hard/6.py @@ -0,0 +1,26 @@ +def extract_nested_value(data, keys): + current = 0 + try: + for key in keys: + current = current[key] + return current + except KeyError: + print("Key not found in the dictionary") + except TypeError + raise ValueError("Invalid key path") + +data = { + "level1": { + "level2": { + "level3": "value" + } + } +} + +keys = ["level1", "level4", "level3"] + +try: + result = extract_nested_value(data, keys) + print("Extracted Value:", result) +except ValueError as e: + print(f"ValueError: {e}") \ No newline at end of file diff --git a/Python2/Hard/7.py b/Python2/Hard/7.py new file mode 100644 index 00000000..1b856071 --- /dev/null +++ b/Python2/Hard/7.py @@ -0,0 +1,33 @@ +import random +import numpy as np + +class Reverse: + def __init__(self, data): + self.data = data + self.index = len(data) + + def __iter__(self): + return self + + def __next__(self): + if self.index <= 0: + raise StopIteration + self.index -= 1 + return self.data[self.index] + + def shuffle_data(self): + try: + self.data = list(np.random.shuffle(self.data)) + except Exception as e: + print("Shuffle error:", e) + +def main(): + rev = Reverse("Python") + rev.shuffle_data() + for char in rev: + print(char, end=" ") + + random_num = random.choice(rev.data) + print("\nRandom character from reversed data:", random_num) + +main() diff --git a/Python2/Hard/8.py b/Python2/Hard/8.py new file mode 100644 index 00000000..15e2813d --- /dev/null +++ b/Python2/Hard/8.py @@ -0,0 +1,26 @@ +import numpy as np +import random + +def modify_list(nested_list): + try: + for i in range(len(nested_list)): + nested_list[i][0] += random.randint(1, 5) + if np.mean(nested_list[i]) > 10: + print("Mean exceeds 10 for sublist:", nested_list[i]) + except TypeError as e: + print("Caught a TypeError:", e) + except IndexError: + print("Sublist is empty, cannot increment") + + return nested_list + +def main(): + nested_list = [[1, 2, 3], [], [4, 5], [6, 'x']] + modified_list = modify_list(nested_list) + for sublist in modified_list: + print(sublist) + + reshaped = np.reshape(nested_list, (2, 2)) + print("Reshaped list:", reshaped) + +main() diff --git a/Python2/Hard/9.py b/Python2/Hard/9.py new file mode 100644 index 00000000..e4ab6159 --- /dev/null +++ b/Python2/Hard/9.py @@ -0,0 +1,38 @@ +import random +import numpy as np + +def fibonacci(n): + if not isinstance(n, int): + raise TypeError("Input must be an integer") + if n == 0: + return 0 + elif n == 1: + return 1 + elif n < 0: + return fibonacci(n + 2) - fibonacci(n + 1) + else: + return fibonacci(n - 1) + fibonacci(n - 2) + +def main(): + try: + num = random.choice([-5, 'ten', 8.5]) + if num < 0: + raise ValueError("Fibonacci sequence is not defined for negative numbers") + + result = fibonacci(num) + print(f"Fibonacci({num}) = {result}") + + reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (2, num // 2)) + print("Reshaped Fibonacci series:", reshaped_result) + + except TypeError as e: + print(f"Caught a TypeError: {e}") + except ValueError: + print("Caught ValueError.") + except RecursionError: + print("Maximum recursion depth exceeded.") + finally: + invalid_sum = fibonacci(5) + None + print("Invalid sum:", invalid_sum) + +main() From da531f06a6e8e2daf05b074b24d1873a550267b5 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 16:54:57 +0530 Subject: [PATCH 17/62] medium level uploaded --- Python2/Medium/1.py | 11 +++++++++++ Python2/Medium/10.py | 9 +++++++++ Python2/Medium/11.py | 13 +++++++++++++ Python2/Medium/12.py | 11 +++++++++++ Python2/Medium/13.py | 13 +++++++++++++ Python2/Medium/14.py | 12 ++++++++++++ Python2/Medium/15.py | 11 +++++++++++ Python2/Medium/16.py | 11 +++++++++++ Python2/Medium/17.py | 15 +++++++++++++++ Python2/Medium/18.py | 13 +++++++++++++ Python2/Medium/19.py | 14 ++++++++++++++ Python2/Medium/2.py | 11 +++++++++++ Python2/Medium/20.py | 13 +++++++++++++ Python2/Medium/21.py | 8 ++++++++ Python2/Medium/22.py | 9 +++++++++ Python2/Medium/23.py | 9 +++++++++ Python2/Medium/24.py | 8 ++++++++ Python2/Medium/25.py | 11 +++++++++++ Python2/Medium/26.py | 12 ++++++++++++ Python2/Medium/27.py | 11 +++++++++++ Python2/Medium/28.py | 8 ++++++++ Python2/Medium/29.py | 9 +++++++++ Python2/Medium/3.py | 10 ++++++++++ Python2/Medium/30.py | 12 ++++++++++++ Python2/Medium/31.py | 8 ++++++++ Python2/Medium/32.py | 12 ++++++++++++ Python2/Medium/33.py | 11 +++++++++++ Python2/Medium/34.py | 11 +++++++++++ Python2/Medium/35.py | 10 ++++++++++ Python2/Medium/36.py | 21 +++++++++++++++++++++ Python2/Medium/37.py | 23 +++++++++++++++++++++++ Python2/Medium/38.py | 10 ++++++++++ Python2/Medium/39.py | 7 +++++++ Python2/Medium/4.py | 11 +++++++++++ Python2/Medium/40.py | 11 +++++++++++ Python2/Medium/41.py | 13 +++++++++++++ Python2/Medium/42.py | 12 ++++++++++++ Python2/Medium/43.py | 19 +++++++++++++++++++ Python2/Medium/44.py | 11 +++++++++++ Python2/Medium/45.py | 13 +++++++++++++ Python2/Medium/46.py | 12 ++++++++++++ Python2/Medium/47.py | 9 +++++++++ Python2/Medium/48.py | 15 +++++++++++++++ Python2/Medium/49.py | 9 +++++++++ Python2/Medium/5.py | 14 ++++++++++++++ Python2/Medium/50.py | 7 +++++++ Python2/Medium/6.py | 14 ++++++++++++++ Python2/Medium/7.py | 11 +++++++++++ Python2/Medium/8.py | 12 ++++++++++++ Python2/Medium/9.py | 13 +++++++++++++ 50 files changed, 583 insertions(+) create mode 100644 Python2/Medium/1.py create mode 100644 Python2/Medium/10.py create mode 100644 Python2/Medium/11.py create mode 100644 Python2/Medium/12.py create mode 100644 Python2/Medium/13.py create mode 100644 Python2/Medium/14.py create mode 100644 Python2/Medium/15.py create mode 100644 Python2/Medium/16.py create mode 100644 Python2/Medium/17.py create mode 100644 Python2/Medium/18.py create mode 100644 Python2/Medium/19.py create mode 100644 Python2/Medium/2.py create mode 100644 Python2/Medium/20.py create mode 100644 Python2/Medium/21.py create mode 100644 Python2/Medium/22.py create mode 100644 Python2/Medium/23.py create mode 100644 Python2/Medium/24.py create mode 100644 Python2/Medium/25.py create mode 100644 Python2/Medium/26.py create mode 100644 Python2/Medium/27.py create mode 100644 Python2/Medium/28.py create mode 100644 Python2/Medium/29.py create mode 100644 Python2/Medium/3.py create mode 100644 Python2/Medium/30.py create mode 100644 Python2/Medium/31.py create mode 100644 Python2/Medium/32.py create mode 100644 Python2/Medium/33.py create mode 100644 Python2/Medium/34.py create mode 100644 Python2/Medium/35.py create mode 100644 Python2/Medium/36.py create mode 100644 Python2/Medium/37.py create mode 100644 Python2/Medium/38.py create mode 100644 Python2/Medium/39.py create mode 100644 Python2/Medium/4.py create mode 100644 Python2/Medium/40.py create mode 100644 Python2/Medium/41.py create mode 100644 Python2/Medium/42.py create mode 100644 Python2/Medium/43.py create mode 100644 Python2/Medium/44.py create mode 100644 Python2/Medium/45.py create mode 100644 Python2/Medium/46.py create mode 100644 Python2/Medium/47.py create mode 100644 Python2/Medium/48.py create mode 100644 Python2/Medium/49.py create mode 100644 Python2/Medium/5.py create mode 100644 Python2/Medium/50.py create mode 100644 Python2/Medium/6.py create mode 100644 Python2/Medium/7.py create mode 100644 Python2/Medium/8.py create mode 100644 Python2/Medium/9.py diff --git a/Python2/Medium/1.py b/Python2/Medium/1.py new file mode 100644 index 00000000..f81fc34e --- /dev/null +++ b/Python2/Medium/1.py @@ -0,0 +1,11 @@ +def factorial(n): + if n == 0: + return 1 + return n * factorial(n - 1) + def main(): + try: + result = factorial(-5) + print(f"Factorial: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/10.py b/Python2/Medium/10.py new file mode 100644 index 00000000..fb8d2ebc --- /dev/null +++ b/Python2/Medium/10.py @@ -0,0 +1,9 @@ +def append_to_list(item, lst=[]): + lst.append(item) + return lst + def main(): + list1 = append_to_list(1) + print(f"List after first append: {list1}") + list2 = append_to_list(2) + print(f"List after second append: {list2}") + main() \ No newline at end of file diff --git a/Python2/Medium/11.py b/Python2/Medium/11.py new file mode 100644 index 00000000..888f7781 --- /dev/null +++ b/Python2/Medium/11.py @@ -0,0 +1,13 @@ + def calculate_average(lst): + total = 0 + for num in lst: + total += num + return total / len(lst) + def main(): + numbers = [] + try: + avg = calculate_average(numbers) + print(f"Average: {avg}") +except ZeroDivisionError as e: + print(f"ZeroDivisionError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/12.py b/Python2/Medium/12.py new file mode 100644 index 00000000..f41c2c07 --- /dev/null +++ b/Python2/Medium/12.py @@ -0,0 +1,11 @@ + def find_number(lst, target): + for num in lst: + if num == target: + print(f"Found {target}") + break + else: + print(f"{target} not found in the list") + def main(): + numbers = [1, 2, 3, 4, 5] + find_number(numbers, 6) + main() \ No newline at end of file diff --git a/Python2/Medium/13.py b/Python2/Medium/13.py new file mode 100644 index 00000000..bf4b1690 --- /dev/null +++ b/Python2/Medium/13.py @@ -0,0 +1,13 @@ + def concatenate_strings(lst): + result = "" + for item in lst: + result += item + return result + def main(): + items = ["Hello", " ", 123, "World!"] + try: + result = concatenate_strings(items) + print(result) + except TypeError as e: + print(f"TypeError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/14.py b/Python2/Medium/14.py new file mode 100644 index 00000000..12ed46e7 --- /dev/null +++ b/Python2/Medium/14.py @@ -0,0 +1,12 @@ +def sort_list(lst): + try: + lst.sort() +return lst + except TypeError as e: + print(f"TypeError: {e}") + def main(): + items = [5, "banana", 3, "apple"] + sorted_items = sort_list(items) + if sorted_items: + print(f"Sorted items: {sorted_items}") + main() \ No newline at end of file diff --git a/Python2/Medium/15.py b/Python2/Medium/15.py new file mode 100644 index 00000000..4a6c141c --- /dev/null +++ b/Python2/Medium/15.py @@ -0,0 +1,11 @@ +def recursive_sum(n): + if n == 0: + return 0 + return n + recursive_sum(n - 1) + def main(): + try: + result = recursive_sum(-5) + print(f"Sum: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/16.py b/Python2/Medium/16.py new file mode 100644 index 00000000..391ca64a --- /dev/null +++ b/Python2/Medium/16.py @@ -0,0 +1,11 @@ + def access_nested_list(nested_list, outer_index, inner_index): + try: + return nested_list[outer_index][inner_index] + except IndexError as e: + print(f"IndexError: {e}") + def main(): + nested_list = [[1, 2, 3], [4, 5], [6]] + result = access_nested_list(nested_list, 1, 5) + if result is not None: + print(f"Accessed value: {result}") + main() \ No newline at end of file diff --git a/Python2/Medium/17.py b/Python2/Medium/17.py new file mode 100644 index 00000000..e5adf202 --- /dev/null +++ b/Python2/Medium/17.py @@ -0,0 +1,15 @@ +def factorial(n): + if n < 0: + return "Factorial not defined for negative numbers" + result = 1 + for i in range(n): + result *= i + return result + def main(): + try: + value = 5 + result = factorial(value) + print(f"Factorial of {value} is {result}") + except Exception as e: + print(f"Error: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/18.py b/Python2/Medium/18.py new file mode 100644 index 00000000..0e276da5 --- /dev/null +++ b/Python2/Medium/18.py @@ -0,0 +1,13 @@ +def filter_positive_numbers(lst): + positive_numbers = [] + for num in lst: + if num > 0: + positive_numbers.append(num) + elif num == 0: + print("Zero is neither positive nor negative") + return positive_numbers + def main(): + numbers = [1, -2, 3, 0, -5, 4] + filtered = filter_positive_numbers(numbers) + print(f"Positive numbers: {filtered}") + main() \ No newline at end of file diff --git a/Python2/Medium/19.py b/Python2/Medium/19.py new file mode 100644 index 00000000..bd2cef5f --- /dev/null +++ b/Python2/Medium/19.py @@ -0,0 +1,14 @@ +def is_prime(n): + if n < 2: + return False + for i in range(2, n // 2): + if n % i == 0: + return False + return True + def main(): + number = 15 +if is_prime(number): + print(f"{number} is a prime number") + else: + print(f"{number} is not a prime number") + main() \ No newline at end of file diff --git a/Python2/Medium/2.py b/Python2/Medium/2.py new file mode 100644 index 00000000..fadd37ce --- /dev/null +++ b/Python2/Medium/2.py @@ -0,0 +1,11 @@ +def get_element(lst, index): + try: + return lst[index] + except IndexError as e: + print(f"IndexError: {e}") + def main(): + numbers = [1, 2, 3] + result = get_element(numbers, 5) + if result is not None: + print(f"Element at index 5: {result}") + main() \ No newline at end of file diff --git a/Python2/Medium/20.py b/Python2/Medium/20.py new file mode 100644 index 00000000..95f1a5b8 --- /dev/null +++ b/Python2/Medium/20.py @@ -0,0 +1,13 @@ +def is_in_range(n, start, end): + if n >= start or n <= end: + return True + return False + def main(): + number = 5 + start = 1 + end = 10 + if is_in_range(number, start, end): + print(f"{number} is within the range [{start}, {end}]") + else: + print(f"{number} is not within the range [{start}, {end}]") + main() \ No newline at end of file diff --git a/Python2/Medium/21.py b/Python2/Medium/21.py new file mode 100644 index 00000000..cd7c65d7 --- /dev/null +++ b/Python2/Medium/21.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 + except ZeroDivisionError: + print('Division by zero') + else: + print('No error') + finally: + print('Done') \ No newline at end of file diff --git a/Python2/Medium/22.py b/Python2/Medium/22.py new file mode 100644 index 00000000..51e48574 --- /dev/null +++ b/Python2/Medium/22.py @@ -0,0 +1,9 @@ + class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): +self.salary += amount + employee = Employee('John', 50000) + employee.give_raise('5000') + print(employee.salary) \ No newline at end of file diff --git a/Python2/Medium/23.py b/Python2/Medium/23.py new file mode 100644 index 00000000..c824d6ea --- /dev/null +++ b/Python2/Medium/23.py @@ -0,0 +1,9 @@ +try: + file = open('non_existent_file.txt', 'r') + content = file.read() + except FileNotFoundError: + print('File not found') + else: + print('File read successfully') + finally: + file.close() \ No newline at end of file diff --git a/Python2/Medium/24.py b/Python2/Medium/24.py new file mode 100644 index 00000000..14e7f370 --- /dev/null +++ b/Python2/Medium/24.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' + student = Student('Alice', 90) + print(student.__str__()) \ No newline at end of file diff --git a/Python2/Medium/25.py b/Python2/Medium/25.py new file mode 100644 index 00000000..0050dd75 --- /dev/null +++ b/Python2/Medium/25.py @@ -0,0 +1,11 @@ + def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config + result = read_config('config.txt') \ No newline at end of file diff --git a/Python2/Medium/26.py b/Python2/Medium/26.py new file mode 100644 index 00000000..549796e5 --- /dev/null +++ b/Python2/Medium/26.py @@ -0,0 +1,12 @@ +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + + def __eq__(self, other): + return self.title == other.title and self.author == other.author + +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" + +print(book1 == book2) diff --git a/Python2/Medium/27.py b/Python2/Medium/27.py new file mode 100644 index 00000000..2aeaac2c --- /dev/null +++ b/Python2/Medium/27.py @@ -0,0 +1,11 @@ +def read_csv(filename): + data = [] + try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) + except FileNotFoundError: + print('CSV file not found') + return data +result = read_csv('data.csv') \ No newline at end of file diff --git a/Python2/Medium/28.py b/Python2/Medium/28.py new file mode 100644 index 00000000..bdaf693a --- /dev/null +++ b/Python2/Medium/28.py @@ -0,0 +1,8 @@ +try: + result = 10 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error, but there was no division either!') +finally: + print('Done') diff --git a/Python2/Medium/29.py b/Python2/Medium/29.py new file mode 100644 index 00000000..f9457def --- /dev/null +++ b/Python2/Medium/29.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise('5000') +print(employee.salary) diff --git a/Python2/Medium/3.py b/Python2/Medium/3.py new file mode 100644 index 00000000..efab262b --- /dev/null +++ b/Python2/Medium/3.py @@ -0,0 +1,10 @@ + def countdown(n): + while n >= 0: + print(n) + n += 1 + def main(): + try: + countdown(5) + except KeyboardInterrupt: + print("Countdown interrupted") +main() \ No newline at end of file diff --git a/Python2/Medium/30.py b/Python2/Medium/30.py new file mode 100644 index 00000000..ac3e3495 --- /dev/null +++ b/Python2/Medium/30.py @@ -0,0 +1,12 @@ + +try: + file = open('non_existent_file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') + file.close() +else + print('File read successfully') +finally: + if file: + file.close() diff --git a/Python2/Medium/31.py b/Python2/Medium/31.py new file mode 100644 index 00000000..3b8bc447 --- /dev/null +++ b/Python2/Medium/31.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.grade()) diff --git a/Python2/Medium/32.py b/Python2/Medium/32.py new file mode 100644 index 00000000..b4208ffb --- /dev/null +++ b/Python2/Medium/32.py @@ -0,0 +1,12 @@ +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') +ne '=' + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') diff --git a/Python2/Medium/33.py b/Python2/Medium/33.py new file mode 100644 index 00000000..3ac4e41d --- /dev/null +++ b/Python2/Medium/33.py @@ -0,0 +1,11 @@ +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + def __eq__(self, other): + if isinstance(other, Book): + return self.title == other.title and self.author == other.author + return False +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" +print(book1 == book2) diff --git a/Python2/Medium/34.py b/Python2/Medium/34.py new file mode 100644 index 00000000..2aeaac2c --- /dev/null +++ b/Python2/Medium/34.py @@ -0,0 +1,11 @@ +def read_csv(filename): + data = [] + try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) + except FileNotFoundError: + print('CSV file not found') + return data +result = read_csv('data.csv') \ No newline at end of file diff --git a/Python2/Medium/35.py b/Python2/Medium/35.py new file mode 100644 index 00000000..968cef11 --- /dev/null +++ b/Python2/Medium/35.py @@ -0,0 +1,10 @@ +def sum_of_elements(lst): + total = 0 + for i in range(len(lst)): + total += lst[i + 1] + return total +def main(): + numbers = [1, 2, 3, 4] + result = sum_of_elements(numbers) + print(f"Sum: {result}") +main() diff --git a/Python2/Medium/36.py b/Python2/Medium/36.py new file mode 100644 index 00000000..1032ac76 --- /dev/null +++ b/Python2/Medium/36.py @@ -0,0 +1,21 @@ +x = 10 + +def modify_variable(): + x = 5 + def inner_function(): + global x + x += 5 + print(f"Modified inner x: {x}") + + inner_function() + print(f"Modified x in outer function: {x}") + +def another_modify_variable(): + x = 20 + print(f"Another modified x: {x}") + +def main(): + modify_variable() + another_modify_variable() + print(f"Final x: {x}") +main() diff --git a/Python2/Medium/37.py b/Python2/Medium/37.py new file mode 100644 index 00000000..c808e037 --- /dev/null +++ b/Python2/Medium/37.py @@ -0,0 +1,23 @@ +def factorial(n): + if n < 0: + return None + result = 1 + while n >= 1: + result *= n + n += 1 + return result + +def memoized_factorial(n, cache={}): + if n in cache: + return cache[n] + if n == 0 or n == 1: + return 1 + cache[n] = n * memoized_factorial(n - 1) + return cache[n] + +def main(): + number = 5 + print(f"Factorial of {number}: {factorial(number)}") + print(f"Memoized Factorial of {number}: {memoized_factorial(number)}") + print(f"Factorial of -1: {factorial(-1)}") +main() diff --git a/Python2/Medium/38.py b/Python2/Medium/38.py new file mode 100644 index 00000000..040f7a40 --- /dev/null +++ b/Python2/Medium/38.py @@ -0,0 +1,10 @@ +def reverse_string(s): + reversed_s = '' + for i in range(len(s)): + reversed_s += s[i] + return reversed_s +def main(): + string = "hello" + result = reverse_string(string) + print(f"Reversed string: {result}") +main() diff --git a/Python2/Medium/39.py b/Python2/Medium/39.py new file mode 100644 index 00000000..8c10eb14 --- /dev/null +++ b/Python2/Medium/39.py @@ -0,0 +1,7 @@ +def sort_dict_by_values(d): + return sorted(d, key=lambda x: x[1]); +def main(): + my_dict = {'a': 3, 'b': 1, 'c': 2}: + result = sort_dict_by_values(my_dict) + print(f"Sorted dictionary: {result}") +main(); diff --git a/Python2/Medium/4.py b/Python2/Medium/4.py new file mode 100644 index 00000000..ca153e03 --- /dev/null +++ b/Python2/Medium/4.py @@ -0,0 +1,11 @@ + def divide(a, b): + try: + return a / b + except: + print("An error occurred") + return None + def main(): + result = divide(10, 0) + if result is not None: + print(f"Result: {result}") + main() \ No newline at end of file diff --git a/Python2/Medium/40.py b/Python2/Medium/40.py new file mode 100644 index 00000000..183ebfb2 --- /dev/null +++ b/Python2/Medium/40.py @@ -0,0 +1,11 @@ +def find_max(lst): + max_val = lst[0] + for i in range(len(lst)): + if lst[i] < max_val: + max_val = lst[i] + return max_val +def main(): + numbers = [1, 4, 2, 8, 3] + result = find_max(numbers) + print(f"Max value: {result}") +main() \ No newline at end of file diff --git a/Python2/Medium/41.py b/Python2/Medium/41.py new file mode 100644 index 00000000..464506b3 --- /dev/null +++ b/Python2/Medium/41.py @@ -0,0 +1,13 @@ +def check_even_odd(lst): + evens = [] + odds = [] + for n in lst: + if n % 2 == 0: + odds.append(n) + else: + evens.append(n) +def main(): + numbers = [1, 2, 3, 4, 5, 6] + evens, odds = check_even_odd(numbers) + print(f"Evens: {evens}, Odds: {odds}") +main() \ No newline at end of file diff --git a/Python2/Medium/42.py b/Python2/Medium/42.py new file mode 100644 index 00000000..935115fe --- /dev/null +++ b/Python2/Medium/42.py @@ -0,0 +1,12 @@ +def add_matrices(mat1, mat2): + result = [] + for i in range(len(mat1)): + for j in range(len(mat2)): + result.append(mat1[i][j] + mat2[i][j]) + return result +def main(): + matrix1 = [[1, 2], [3, 4]] + matrix2 = [[5, 6], [7, 8]] + result = add_matrices(matrix1, matrix2) + print(f"Matrix sum: {result}") +main() diff --git a/Python2/Medium/43.py b/Python2/Medium/43.py new file mode 100644 index 00000000..bd7afd23 --- /dev/null +++ b/Python2/Medium/43.py @@ -0,0 +1,19 @@ +def merge_sorted_lists(lst1, lst2): + merged = [] + i = j = 0 + while i < len(lst1) and j < len(lst2): + if lst1[i] > lst2[j]: + merged.append(lst1[i]) + i += 1 + else: + merged.append(lst2[j]) + j += 1 + merged += lst1[i:] + merged += lst2[j:] + return merged +def main(): + list1 = [1, 3, 5] + list2 = [2, 4, 6] + result = merge_sorted_lists(list1, list2) + print(f"Merged list: {result}") +main() diff --git a/Python2/Medium/44.py b/Python2/Medium/44.py new file mode 100644 index 00000000..f789e72a --- /dev/null +++ b/Python2/Medium/44.py @@ -0,0 +1,11 @@ +def power(base, exp): + if exp == 0: + return 1 + else: + return base * power(base, exp - 2) +def main(): + base = 2 + exp = 3 + result = power(base, exp) + print(f"{base}^{exp} = {result}") +main() diff --git a/Python2/Medium/45.py b/Python2/Medium/45.py new file mode 100644 index 00000000..87364450 --- /dev/null +++ b/Python2/Medium/45.py @@ -0,0 +1,13 @@ +def is_even(n): + if n % 2 == 1: + return True + else: + return False +def main(): + number = 4 + result = is_even(number) + if result: + print(f"{number} is even") + else: + print(f"{number} is odd") + main() \ No newline at end of file diff --git a/Python2/Medium/46.py b/Python2/Medium/46.py new file mode 100644 index 00000000..40f34aa0 --- /dev/null +++ b/Python2/Medium/46.py @@ -0,0 +1,12 @@ +def get_value(d, key): + try: + return d[key] + except KeyError as e: + print(f"KeyError: {e}") + return None +def main(): + my_dict = {"a": 1, "b": 2} + value = get_value(my_dict, "c") + if value is not None: + print(f"Value for key 'c': {value}") +main() diff --git a/Python2/Medium/47.py b/Python2/Medium/47.py new file mode 100644 index 00000000..41414d2a --- /dev/null +++ b/Python2/Medium/47.py @@ -0,0 +1,9 @@ +try: + file = open('non_existent_file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() diff --git a/Python2/Medium/48.py b/Python2/Medium/48.py new file mode 100644 index 00000000..2f48ec83 --- /dev/null +++ b/Python2/Medium/48.py @@ -0,0 +1,15 @@ +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n - 1) + fibonacci(n - 2) +def main(): +try: +Intermediate Level Code Snippets 18 + result = fibonacci(-3) + print(f"Fibonacci: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") +main() diff --git a/Python2/Medium/49.py b/Python2/Medium/49.py new file mode 100644 index 00000000..f9457def --- /dev/null +++ b/Python2/Medium/49.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise('5000') +print(employee.salary) diff --git a/Python2/Medium/5.py b/Python2/Medium/5.py new file mode 100644 index 00000000..2eb4319b --- /dev/null +++ b/Python2/Medium/5.py @@ -0,0 +1,14 @@ +def filter_strings(lst): + filtered = [] + for x in lst: + try: + if x > 5: + filtered.append(x) + except TypeError as e: + print(f"TypeError: {e}") + return filtered + def main(): + values = ["apple", 10, "banana", 7] + result = filter_strings(values) + print(f"Filtered values: {result}") + main() \ No newline at end of file diff --git a/Python2/Medium/50.py b/Python2/Medium/50.py new file mode 100644 index 00000000..61a9b882 --- /dev/null +++ b/Python2/Medium/50.py @@ -0,0 +1,7 @@ +def sort_dict_by_values(d): + return sorted(d, key=lambda x: x[1]) +def main(): + my_dict = {'a': 3, 'b': 1, 'c': 2} + result = sort_dict_by_values(my_dict) + print(f"Sorted dictionary: {result}") +main() diff --git a/Python2/Medium/6.py b/Python2/Medium/6.py new file mode 100644 index 00000000..05013e2b --- /dev/null +++ b/Python2/Medium/6.py @@ -0,0 +1,14 @@ + def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 +else: + return fibonacci(n - 1) + fibonacci(n - 2) + def main(): + try: + result = fibonacci(-3) + print(f"Fibonacci: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/7.py b/Python2/Medium/7.py new file mode 100644 index 00000000..1de7cf1a --- /dev/null +++ b/Python2/Medium/7.py @@ -0,0 +1,11 @@ +def safe_divide(a, b): + if b == 0: + return "Cannot divide by zero" + return a / b + def main(): + try: + print(safe_divide(10, 0)) + print(safe_divide(0, 0)) + except ZeroDivisionError as e: + print(f"ZeroDivisionError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/8.py b/Python2/Medium/8.py new file mode 100644 index 00000000..6b4ab2f8 --- /dev/null +++ b/Python2/Medium/8.py @@ -0,0 +1,12 @@ +def get_value(d, key): + try: + return d[key] + except KeyError as e: + print(f"KeyError: {e}") + return None + def main(): + my_dict = {"a": 1, "b": 2} + value = get_value(my_dict, "c") + if value is not None: + print(f"Value for key 'c': {value}") + main() \ No newline at end of file diff --git a/Python2/Medium/9.py b/Python2/Medium/9.py new file mode 100644 index 00000000..827e612a --- /dev/null +++ b/Python2/Medium/9.py @@ -0,0 +1,13 @@ +def is_even(n): + if n % 2 == 1: + return True + else: + return False + def main(): + number = 4 + result = is_even(number) + if result: + print(f"{number} is even") + else: + print(f"{number} is odd") + main() \ No newline at end of file From 3ca1644b054193be13b3c59e133af8281186434b Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:43:20 +0530 Subject: [PATCH 18/62] Delete Java directory --- Java/j1.java | 6 ------ Java/j10.java | 7 ------- Java/j100.java | 6 ------ Java/j101.java | 6 ------ Java/j102.java | 7 ------- Java/j103.java | 7 ------- Java/j104.java | 6 ------ Java/j105.java | 6 ------ Java/j106.java | 6 ------ Java/j107.java | 6 ------ Java/j108.java | 5 ----- Java/j109.java | 8 -------- Java/j11.java | 6 ------ Java/j110.java | 6 ------ Java/j111.java | 8 -------- Java/j112.java | 6 ------ Java/j113.java | 7 ------- Java/j114.java | 6 ------ Java/j115.java | 6 ------ Java/j116.java | 7 ------- Java/j117.java | 6 ------ Java/j118.java | 6 ------ Java/j119.java | 7 ------- Java/j12.java | 6 ------ Java/j120.java | 7 ------- Java/j121.java | 7 ------- Java/j122.java | 8 -------- Java/j123.java | 8 -------- Java/j124.java | 7 ------- Java/j125.java | 7 ------- Java/j126.java | 6 ------ Java/j127.java | 6 ------ Java/j128.java | 7 ------- Java/j129.java | 8 -------- Java/j13.java | 7 ------- Java/j130.java | 7 ------- Java/j131.java | 8 -------- Java/j132.java | 7 ------- Java/j133.java | 6 ------ Java/j134.java | 7 ------- Java/j135.java | 6 ------ Java/j136.java | 6 ------ Java/j137.java | 7 ------- Java/j138.java | 6 ------ Java/j139.java | 6 ------ Java/j14.java | 6 ------ Java/j140.java | 6 ------ Java/j141.java | 7 ------- Java/j142.java | 8 -------- Java/j143.java | 6 ------ Java/j144.java | 7 ------- Java/j145.java | 7 ------- Java/j146.java | 8 -------- Java/j147.java | 6 ------ Java/j148.java | 6 ------ Java/j149.java | 7 ------- Java/j15.java | 6 ------ Java/j150.java | 8 -------- Java/j151.java | 8 -------- Java/j152.java | 6 ------ Java/j153.java | 6 ------ Java/j154.java | 8 -------- Java/j155.java | 6 ------ Java/j156.java | 6 ------ Java/j157.java | 7 ------- Java/j158.java | 6 ------ Java/j159.java | 7 ------- Java/j16.java | 8 -------- Java/j160.java | 6 ------ Java/j161.java | 8 -------- Java/j162.java | 8 -------- Java/j163.java | 6 ------ Java/j164.java | 6 ------ Java/j165.java | 6 ------ Java/j166.java | 7 ------- Java/j167.java | 7 ------- Java/j168.java | 6 ------ Java/j169.java | 6 ------ Java/j17.java | 6 ------ Java/j170.java | 7 ------- Java/j171.java | 6 ------ Java/j172.java | 7 ------- Java/j173.java | 6 ------ Java/j174.java | 7 ------- Java/j175.java | 6 ------ Java/j176.java | 6 ------ Java/j177.java | 8 -------- Java/j178.java | 6 ------ Java/j179.java | 7 ------- Java/j18.java | 8 -------- Java/j180.java | 7 ------- Java/j181.java | 5 ----- Java/j182.java | 7 ------- Java/j183.java | 8 -------- Java/j184.java | 7 ------- Java/j185.java | 7 ------- Java/j186.java | 7 ------- Java/j187.java | 6 ------ Java/j188.java | 8 -------- Java/j189.java | 10 ---------- Java/j19.java | 7 ------- Java/j190.java | 6 ------ Java/j191.java | 7 ------- Java/j192.java | 6 ------ Java/j193.java | 6 ------ Java/j194.java | 6 ------ Java/j195.java | 6 ------ Java/j196.java | 7 ------- Java/j197.java | 6 ------ Java/j198.java | 7 ------- Java/j199.java | 6 ------ Java/j2.java | 6 ------ Java/j20.java | 6 ------ Java/j200.java | 7 ------- Java/j201.java | 6 ------ Java/j202.java | 6 ------ Java/j203.java | 8 -------- Java/j204.java | 6 ------ Java/j205.java | 6 ------ Java/j206.java | 7 ------- Java/j207.java | 6 ------ Java/j208.java | 6 ------ Java/j209.java | 6 ------ Java/j21.java | 7 ------- Java/j210.java | 7 ------- Java/j211.java | 7 ------- Java/j212.java | 6 ------ Java/j213.java | 6 ------ Java/j214.java | 8 -------- Java/j215.java | 6 ------ Java/j216.java | 6 ------ Java/j217.java | 7 ------- Java/j218.java | 7 ------- Java/j219.java | 5 ----- Java/j22.java | 6 ------ Java/j220.java | 6 ------ Java/j221.java | 6 ------ Java/j222.java | 6 ------ Java/j223.java | 7 ------- Java/j224.java | 7 ------- Java/j225.java | 7 ------- Java/j226.java | 6 ------ Java/j227.java | 6 ------ Java/j228.java | 6 ------ Java/j229.java | 6 ------ Java/j23.java | 6 ------ Java/j230.java | 7 ------- Java/j231.java | 7 ------- Java/j232.java | 7 ------- Java/j233.java | 8 -------- Java/j234.java | 6 ------ Java/j235.java | 6 ------ Java/j236.java | 6 ------ Java/j237.java | 6 ------ Java/j238.java | 8 -------- Java/j239.java | 6 ------ Java/j24.java | 7 ------- Java/j240.java | 6 ------ Java/j241.java | 6 ------ Java/j242.java | 6 ------ Java/j243.java | 6 ------ Java/j244.java | 6 ------ Java/j245.java | 6 ------ Java/j246.java | 7 ------- Java/j247.java | 8 -------- Java/j248.java | 6 ------ Java/j249.java | 6 ------ Java/j25.java | 7 ------- Java/j250.java | 6 ------ Java/j26.java | 6 ------ Java/j27.java | 8 -------- Java/j28.java | 7 ------- Java/j29.java | 7 ------- Java/j3.java | 6 ------ Java/j30.java | 6 ------ Java/j31.java | 6 ------ Java/j32.java | 7 ------- Java/j33.java | 6 ------ Java/j34.java | 6 ------ Java/j35.java | 6 ------ Java/j36.java | 6 ------ Java/j37.java | 7 ------- Java/j38.java | 6 ------ Java/j39.java | 6 ------ Java/j4.java | 7 ------- Java/j40.java | 6 ------ Java/j41.java | 7 ------- Java/j42.java | 5 ----- Java/j43.java | 6 ------ Java/j44.java | 7 ------- Java/j45.java | 6 ------ Java/j46.java | 6 ------ Java/j47.java | 7 ------- Java/j48.java | 6 ------ Java/j49.java | 7 ------- Java/j5.java | 6 ------ Java/j50.java | 6 ------ Java/j51.java | 8 -------- Java/j52.java | 6 ------ Java/j53.java | 6 ------ Java/j54.java | 7 ------- Java/j55.java | 6 ------ Java/j56.java | 7 ------- Java/j57.java | 6 ------ Java/j58.java | 7 ------- Java/j59.java | 6 ------ Java/j6.java | 6 ------ Java/j60.java | 7 ------- Java/j61.java | 8 -------- Java/j62.java | 9 --------- Java/j63.java | 11 ----------- Java/j64.java | 6 ------ Java/j65.java | 8 -------- Java/j66.java | 7 ------- Java/j67.java | 6 ------ Java/j68.java | 6 ------ Java/j69.java | 6 ------ Java/j7.java | 6 ------ Java/j70.java | 7 ------- Java/j71.java | 6 ------ Java/j72.java | 8 -------- Java/j73.java | 8 -------- Java/j74.java | 7 ------- Java/j75.java | 8 -------- Java/j76.java | 6 ------ Java/j77.java | 6 ------ Java/j78.java | 7 ------- Java/j79.java | 6 ------ Java/j8.java | 7 ------- Java/j80.java | 7 ------- Java/j81.java | 7 ------- Java/j82.java | 7 ------- Java/j83.java | 7 ------- Java/j84.java | 9 --------- Java/j85.java | 6 ------ Java/j86.java | 8 -------- Java/j87.java | 6 ------ Java/j88.java | 5 ----- Java/j89.java | 6 ------ Java/j9.java | 7 ------- Java/j90.java | 6 ------ Java/j91.java | 6 ------ Java/j92.java | 7 ------- Java/j93.java | 8 -------- Java/j94.java | 6 ------ Java/j95.java | 6 ------ Java/j96.java | 6 ------ Java/j97.java | 7 ------- Java/j98.java | 7 ------- Java/j99.java | 6 ------ Java/temp.txt | 1 - 251 files changed, 1654 deletions(-) delete mode 100644 Java/j1.java delete mode 100644 Java/j10.java delete mode 100644 Java/j100.java delete mode 100644 Java/j101.java delete mode 100644 Java/j102.java delete mode 100644 Java/j103.java delete mode 100644 Java/j104.java delete mode 100644 Java/j105.java delete mode 100644 Java/j106.java delete mode 100644 Java/j107.java delete mode 100644 Java/j108.java delete mode 100644 Java/j109.java delete mode 100644 Java/j11.java delete mode 100644 Java/j110.java delete mode 100644 Java/j111.java delete mode 100644 Java/j112.java delete mode 100644 Java/j113.java delete mode 100644 Java/j114.java delete mode 100644 Java/j115.java delete mode 100644 Java/j116.java delete mode 100644 Java/j117.java delete mode 100644 Java/j118.java delete mode 100644 Java/j119.java delete mode 100644 Java/j12.java delete mode 100644 Java/j120.java delete mode 100644 Java/j121.java delete mode 100644 Java/j122.java delete mode 100644 Java/j123.java delete mode 100644 Java/j124.java delete mode 100644 Java/j125.java delete mode 100644 Java/j126.java delete mode 100644 Java/j127.java delete mode 100644 Java/j128.java delete mode 100644 Java/j129.java delete mode 100644 Java/j13.java delete mode 100644 Java/j130.java delete mode 100644 Java/j131.java delete mode 100644 Java/j132.java delete mode 100644 Java/j133.java delete mode 100644 Java/j134.java delete mode 100644 Java/j135.java delete mode 100644 Java/j136.java delete mode 100644 Java/j137.java delete mode 100644 Java/j138.java delete mode 100644 Java/j139.java delete mode 100644 Java/j14.java delete mode 100644 Java/j140.java delete mode 100644 Java/j141.java delete mode 100644 Java/j142.java delete mode 100644 Java/j143.java delete mode 100644 Java/j144.java delete mode 100644 Java/j145.java delete mode 100644 Java/j146.java delete mode 100644 Java/j147.java delete mode 100644 Java/j148.java delete mode 100644 Java/j149.java delete mode 100644 Java/j15.java delete mode 100644 Java/j150.java delete mode 100644 Java/j151.java delete mode 100644 Java/j152.java delete mode 100644 Java/j153.java delete mode 100644 Java/j154.java delete mode 100644 Java/j155.java delete mode 100644 Java/j156.java delete mode 100644 Java/j157.java delete mode 100644 Java/j158.java delete mode 100644 Java/j159.java delete mode 100644 Java/j16.java delete mode 100644 Java/j160.java delete mode 100644 Java/j161.java delete mode 100644 Java/j162.java delete mode 100644 Java/j163.java delete mode 100644 Java/j164.java delete mode 100644 Java/j165.java delete mode 100644 Java/j166.java delete mode 100644 Java/j167.java delete mode 100644 Java/j168.java delete mode 100644 Java/j169.java delete mode 100644 Java/j17.java delete mode 100644 Java/j170.java delete mode 100644 Java/j171.java delete mode 100644 Java/j172.java delete mode 100644 Java/j173.java delete mode 100644 Java/j174.java delete mode 100644 Java/j175.java delete mode 100644 Java/j176.java delete mode 100644 Java/j177.java delete mode 100644 Java/j178.java delete mode 100644 Java/j179.java delete mode 100644 Java/j18.java delete mode 100644 Java/j180.java delete mode 100644 Java/j181.java delete mode 100644 Java/j182.java delete mode 100644 Java/j183.java delete mode 100644 Java/j184.java delete mode 100644 Java/j185.java delete mode 100644 Java/j186.java delete mode 100644 Java/j187.java delete mode 100644 Java/j188.java delete mode 100644 Java/j189.java delete mode 100644 Java/j19.java delete mode 100644 Java/j190.java delete mode 100644 Java/j191.java delete mode 100644 Java/j192.java delete mode 100644 Java/j193.java delete mode 100644 Java/j194.java delete mode 100644 Java/j195.java delete mode 100644 Java/j196.java delete mode 100644 Java/j197.java delete mode 100644 Java/j198.java delete mode 100644 Java/j199.java delete mode 100644 Java/j2.java delete mode 100644 Java/j20.java delete mode 100644 Java/j200.java delete mode 100644 Java/j201.java delete mode 100644 Java/j202.java delete mode 100644 Java/j203.java delete mode 100644 Java/j204.java delete mode 100644 Java/j205.java delete mode 100644 Java/j206.java delete mode 100644 Java/j207.java delete mode 100644 Java/j208.java delete mode 100644 Java/j209.java delete mode 100644 Java/j21.java delete mode 100644 Java/j210.java delete mode 100644 Java/j211.java delete mode 100644 Java/j212.java delete mode 100644 Java/j213.java delete mode 100644 Java/j214.java delete mode 100644 Java/j215.java delete mode 100644 Java/j216.java delete mode 100644 Java/j217.java delete mode 100644 Java/j218.java delete mode 100644 Java/j219.java delete mode 100644 Java/j22.java delete mode 100644 Java/j220.java delete mode 100644 Java/j221.java delete mode 100644 Java/j222.java delete mode 100644 Java/j223.java delete mode 100644 Java/j224.java delete mode 100644 Java/j225.java delete mode 100644 Java/j226.java delete mode 100644 Java/j227.java delete mode 100644 Java/j228.java delete mode 100644 Java/j229.java delete mode 100644 Java/j23.java delete mode 100644 Java/j230.java delete mode 100644 Java/j231.java delete mode 100644 Java/j232.java delete mode 100644 Java/j233.java delete mode 100644 Java/j234.java delete mode 100644 Java/j235.java delete mode 100644 Java/j236.java delete mode 100644 Java/j237.java delete mode 100644 Java/j238.java delete mode 100644 Java/j239.java delete mode 100644 Java/j24.java delete mode 100644 Java/j240.java delete mode 100644 Java/j241.java delete mode 100644 Java/j242.java delete mode 100644 Java/j243.java delete mode 100644 Java/j244.java delete mode 100644 Java/j245.java delete mode 100644 Java/j246.java delete mode 100644 Java/j247.java delete mode 100644 Java/j248.java delete mode 100644 Java/j249.java delete mode 100644 Java/j25.java delete mode 100644 Java/j250.java delete mode 100644 Java/j26.java delete mode 100644 Java/j27.java delete mode 100644 Java/j28.java delete mode 100644 Java/j29.java delete mode 100644 Java/j3.java delete mode 100644 Java/j30.java delete mode 100644 Java/j31.java delete mode 100644 Java/j32.java delete mode 100644 Java/j33.java delete mode 100644 Java/j34.java delete mode 100644 Java/j35.java delete mode 100644 Java/j36.java delete mode 100644 Java/j37.java delete mode 100644 Java/j38.java delete mode 100644 Java/j39.java delete mode 100644 Java/j4.java delete mode 100644 Java/j40.java delete mode 100644 Java/j41.java delete mode 100644 Java/j42.java delete mode 100644 Java/j43.java delete mode 100644 Java/j44.java delete mode 100644 Java/j45.java delete mode 100644 Java/j46.java delete mode 100644 Java/j47.java delete mode 100644 Java/j48.java delete mode 100644 Java/j49.java delete mode 100644 Java/j5.java delete mode 100644 Java/j50.java delete mode 100644 Java/j51.java delete mode 100644 Java/j52.java delete mode 100644 Java/j53.java delete mode 100644 Java/j54.java delete mode 100644 Java/j55.java delete mode 100644 Java/j56.java delete mode 100644 Java/j57.java delete mode 100644 Java/j58.java delete mode 100644 Java/j59.java delete mode 100644 Java/j6.java delete mode 100644 Java/j60.java delete mode 100644 Java/j61.java delete mode 100644 Java/j62.java delete mode 100644 Java/j63.java delete mode 100644 Java/j64.java delete mode 100644 Java/j65.java delete mode 100644 Java/j66.java delete mode 100644 Java/j67.java delete mode 100644 Java/j68.java delete mode 100644 Java/j69.java delete mode 100644 Java/j7.java delete mode 100644 Java/j70.java delete mode 100644 Java/j71.java delete mode 100644 Java/j72.java delete mode 100644 Java/j73.java delete mode 100644 Java/j74.java delete mode 100644 Java/j75.java delete mode 100644 Java/j76.java delete mode 100644 Java/j77.java delete mode 100644 Java/j78.java delete mode 100644 Java/j79.java delete mode 100644 Java/j8.java delete mode 100644 Java/j80.java delete mode 100644 Java/j81.java delete mode 100644 Java/j82.java delete mode 100644 Java/j83.java delete mode 100644 Java/j84.java delete mode 100644 Java/j85.java delete mode 100644 Java/j86.java delete mode 100644 Java/j87.java delete mode 100644 Java/j88.java delete mode 100644 Java/j89.java delete mode 100644 Java/j9.java delete mode 100644 Java/j90.java delete mode 100644 Java/j91.java delete mode 100644 Java/j92.java delete mode 100644 Java/j93.java delete mode 100644 Java/j94.java delete mode 100644 Java/j95.java delete mode 100644 Java/j96.java delete mode 100644 Java/j97.java delete mode 100644 Java/j98.java delete mode 100644 Java/j99.java delete mode 100644 Java/temp.txt diff --git a/Java/j1.java b/Java/j1.java deleted file mode 100644 index 24eb8e4b..00000000 --- a/Java/j1.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5 - System.out.println(x); - } -} diff --git a/Java/j10.java b/Java/j10.java deleted file mode 100644 index 0669f78b..00000000 --- a/Java/j10.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "John"; - char letter = name.charAt(5); - System.out.println(letter); - } -} diff --git a/Java/j100.java b/Java/j100.java deleted file mode 100644 index 47f78cd4..00000000 --- a/Java/j100.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] names = {"Alice", "Bob"}; - System.out.println(names.get(0)); - } -} diff --git a/Java/j101.java b/Java/j101.java deleted file mode 100644 index 04d37169..00000000 --- a/Java/j101.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.abs(); - System.out.println(x); - } -} diff --git a/Java/j102.java b/Java/j102.java deleted file mode 100644 index 55dba6bb..00000000 --- a/Java/j102.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 5) { - System.out.println(i); - } - } -} diff --git a/Java/j103.java b/Java/j103.java deleted file mode 100644 index 7541cfb5..00000000 --- a/Java/j103.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - numbers.add(10); - System.out.println(numbers.get(0)); - } -} diff --git a/Java/j104.java b/Java/j104.java deleted file mode 100644 index 91fcf538..00000000 --- a/Java/j104.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] items = {"apple", "banana"}; - System.out.println(items[2]); - } -} diff --git a/Java/j105.java b/Java/j105.java deleted file mode 100644 index 6cd8dfcd..00000000 --- a/Java/j105.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "java"; - System.out.println(text.ToUpperCase()); - } -} diff --git a/Java/j106.java b/Java/j106.java deleted file mode 100644 index a64ab5fd..00000000 --- a/Java/j106.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x; - System.out.println(x); - } -} diff --git a/Java/j107.java b/Java/j107.java deleted file mode 100644 index 2128aa29..00000000 --- a/Java/j107.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers.toString()); - } -} diff --git a/Java/j108.java b/Java/j108.java deleted file mode 100644 index afb85272..00000000 --- a/Java/j108.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(5. / 0); - } -} diff --git a/Java/j109.java b/Java/j109.java deleted file mode 100644 index d5df4b28..00000000 --- a/Java/j109.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i : arr) { - arr[i] = i * 2; - } - } -} diff --git a/Java/j11.java b/Java/j11.java deleted file mode 100644 index 402ae089..00000000 --- a/Java/j11.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isValid = True; - System.out.println(isValid); - } -} diff --git a/Java/j110.java b/Java/j110.java deleted file mode 100644 index 73544d10..00000000 --- a/Java/j110.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.pow(2); - System.out.println(x); - } -} diff --git a/Java/j111.java b/Java/j111.java deleted file mode 100644 index 7c4d3274..00000000 --- a/Java/j111.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i = 0; i <= arr.length; i++) { - arr[i] = i; - } - } -} diff --git a/Java/j112.java b/Java/j112.java deleted file mode 100644 index 52ca32df..00000000 --- a/Java/j112.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - arr.add(5); - } -} diff --git a/Java/j113.java b/Java/j113.java deleted file mode 100644 index a81fbba9..00000000 --- a/Java/j113.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - s.toLowerCase; - System.out.println(s); - } -} diff --git a/Java/j114.java b/Java/j114.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j114.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j115.java b/Java/j115.java deleted file mode 100644 index b895ac41..00000000 --- a/Java/j115.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr.length()); - } -} diff --git a/Java/j116.java b/Java/j116.java deleted file mode 100644 index d0983e18..00000000 --- a/Java/j116.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "apple"; - s.charAt(5); - System.out.println(s); - } -} diff --git a/Java/j117.java b/Java/j117.java deleted file mode 100644 index ff52a4d9..00000000 --- a/Java/j117.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = 100; - System.out.println(str); - } -} diff --git a/Java/j118.java b/Java/j118.java deleted file mode 100644 index effdaa79..00000000 --- a/Java/j118.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[-10]; - System.out.println(numbers.length); - } -} diff --git a/Java/j119.java b/Java/j119.java deleted file mode 100644 index 110543be..00000000 --- a/Java/j119.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("Alice"); - System.out.println(list[0]); - } -} diff --git a/Java/j12.java b/Java/j12.java deleted file mode 100644 index 0ac2316e..00000000 --- a/Java/j12.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int number = "50"; - System.out.println(number); - } -} diff --git a/Java/j120.java b/Java/j120.java deleted file mode 100644 index 02893275..00000000 --- a/Java/j120.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List names = new ArrayList<>(); - names.add("John", "Doe"); - System.out.println(names); - } -} diff --git a/Java/j121.java b/Java/j121.java deleted file mode 100644 index 603148d5..00000000 --- a/Java/j121.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int result = Math.pow(a, 2); - System.out.println(result); - } -} diff --git a/Java/j122.java b/Java/j122.java deleted file mode 100644 index 393a2af9..00000000 --- a/Java/j122.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - if (x > 10) - System.out.println("x is greater than 10"); - System.out.println("This will always print"); - } -} diff --git a/Java/j123.java b/Java/j123.java deleted file mode 100644 index 715095e9..00000000 --- a/Java/j123.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int num = 0; - do { - System.out.println(num); - } while num < 5; - } -} diff --git a/Java/j124.java b/Java/j124.java deleted file mode 100644 index b681b8b0..00000000 --- a/Java/j124.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String s = (String) a; - System.out.println(s); - } -} diff --git a/Java/j125.java b/Java/j125.java deleted file mode 100644 index a57cb017..00000000 --- a/Java/j125.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = "hello"; - str.concat(" world"); - System.out.println(str); - } -} diff --git a/Java/j126.java b/Java/j126.java deleted file mode 100644 index 3f771e9d..00000000 --- a/Java/j126.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - System.out.println("Square of x is: " + Math.square(x)); - } -} diff --git a/Java/j127.java b/Java/j127.java deleted file mode 100644 index 38706658..00000000 --- a/Java/j127.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] colors = {"red", "green", "blue"}; - System.out.println(colors[3]); - } -} diff --git a/Java/j128.java b/Java/j128.java deleted file mode 100644 index f34b0230..00000000 --- a/Java/j128.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "Alice"; - char letter = name[0]; - System.out.println(letter); - } -} diff --git a/Java/j129.java b/Java/j129.java deleted file mode 100644 index 00c931f9..00000000 --- a/Java/j129.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int i = 0; - for (; i < 5) { - System.out.println(i); - } - } -} diff --git a/Java/j13.java b/Java/j13.java deleted file mode 100644 index bb6808a2..00000000 --- a/Java/j13.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - System.out.println(a.equals(b)); - } -} diff --git a/Java/j130.java b/Java/j130.java deleted file mode 100644 index 036f27ce..00000000 --- a/Java/j130.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String b = (String) a; - System.out.println(b); - } -} diff --git a/Java/j131.java b/Java/j131.java deleted file mode 100644 index 071f63be..00000000 --- a/Java/j131.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 5) { - System.out.println(i); - } - System.out.println(i); - } -} diff --git a/Java/j132.java b/Java/j132.java deleted file mode 100644 index 421c0da7..00000000 --- a/Java/j132.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "java"; - s.replace('a', "o"); - System.out.println(s); - } -} diff --git a/Java/j133.java b/Java/j133.java deleted file mode 100644 index 3c0f32ab..00000000 --- a/Java/j133.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a++); - } -} diff --git a/Java/j134.java b/Java/j134.java deleted file mode 100644 index 8006c3d4..00000000 --- a/Java/j134.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - numbers.add(5); - System.out.println(numbers.get(0)); - } -} diff --git a/Java/j135.java b/Java/j135.java deleted file mode 100644 index 82ccb17d..00000000 --- a/Java/j135.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = null; - System.out.println(message.length()); - } -} diff --git a/Java/j136.java b/Java/j136.java deleted file mode 100644 index c2d6467a..00000000 --- a/Java/j136.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char c = 'Hello'; - System.out.println(c); - } -} diff --git a/Java/j137.java b/Java/j137.java deleted file mode 100644 index c57f8f3f..00000000 --- a/Java/j137.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String s = Integer.toString(a); - System.out.println(s * 2); - } -} diff --git a/Java/j138.java b/Java/j138.java deleted file mode 100644 index 332f8a01..00000000 --- a/Java/j138.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.abs(); - System.out.println(x); - } -} diff --git a/Java/j139.java b/Java/j139.java deleted file mode 100644 index b6be7c26..00000000 --- a/Java/j139.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"apple", "banana", "orange"}; - System.out.println(arr.size()); - } -} diff --git a/Java/j14.java b/Java/j14.java deleted file mode 100644 index 74f374ce..00000000 --- a/Java/j14.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char ch = 'abc'; - System.out.println(ch); - } -} diff --git a/Java/j140.java b/Java/j140.java deleted file mode 100644 index 8efcdd08..00000000 --- a/Java/j140.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5 / 0; - System.out.println(x); - } -} diff --git a/Java/j141.java b/Java/j141.java deleted file mode 100644 index 4992a0f0..00000000 --- a/Java/j141.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - String s = (String) a; - System.out.println(s); - } -} diff --git a/Java/j142.java b/Java/j142.java deleted file mode 100644 index 6a188364..00000000 --- a/Java/j142.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - int result = a + b; - System.out.println(result); - } -} diff --git a/Java/j143.java b/Java/j143.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j143.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j144.java b/Java/j144.java deleted file mode 100644 index c8310967..00000000 --- a/Java/j144.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - double result = a / 0; - System.out.println(result); - } -} diff --git a/Java/j145.java b/Java/j145.java deleted file mode 100644 index da8ac1cd..00000000 --- a/Java/j145.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - s.concat("world"); - System.out.println(s); - } -} diff --git a/Java/j146.java b/Java/j146.java deleted file mode 100644 index 78dc9f7e..00000000 --- a/Java/j146.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - if (x > 0) - System.out.println("Positive"); - System.out.println("Always printed"); - } -} diff --git a/Java/j147.java b/Java/j147.java deleted file mode 100644 index 1dd31ae2..00000000 --- a/Java/j147.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]{1, 2, 3}; - System.out.println(arr[0]); - } -} diff --git a/Java/j148.java b/Java/j148.java deleted file mode 100644 index eaee4844..00000000 --- a/Java/j148.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name; - System.out.println(name); - } -} diff --git a/Java/j149.java b/Java/j149.java deleted file mode 100644 index fb97dc15..00000000 --- a/Java/j149.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5.0; - int result = x; - System.out.println(result); - } -} diff --git a/Java/j15.java b/Java/j15.java deleted file mode 100644 index 4c38504c..00000000 --- a/Java/j15.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isValid = 0; - System.out.println(isValid); - } -} diff --git a/Java/j150.java b/Java/j150.java deleted file mode 100644 index 50d04347..00000000 --- a/Java/j150.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int num = 10; - if (num = 10) { - System.out.println("Number is 10"); - } - } -} diff --git a/Java/j151.java b/Java/j151.java deleted file mode 100644 index 1f455e30..00000000 --- a/Java/j151.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - for (int i : arr) { - arr[i] = i * 2; - } - } -} diff --git a/Java/j152.java b/Java/j152.java deleted file mode 100644 index e883b0b7..00000000 --- a/Java/j152.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - arr[3] = 10; - } -} diff --git a/Java/j153.java b/Java/j153.java deleted file mode 100644 index e28e908d..00000000 --- a/Java/j153.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a = 10); - } -} diff --git a/Java/j154.java b/Java/j154.java deleted file mode 100644 index d3324af5..00000000 --- a/Java/j154.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - int b = 0; - int result = a / b; - System.out.println(result); - } -} diff --git a/Java/j155.java b/Java/j155.java deleted file mode 100644 index 2410b07f..00000000 --- a/Java/j155.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x.equals(10)); - } -} diff --git a/Java/j156.java b/Java/j156.java deleted file mode 100644 index fb2e0bdf..00000000 --- a/Java/j156.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 10 / 0; - System.out.println(x); - } -} diff --git a/Java/j157.java b/Java/j157.java deleted file mode 100644 index bcea9397..00000000 --- a/Java/j157.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - char firstChar = text[0]; - System.out.println(firstChar); - } -} diff --git a/Java/j158.java b/Java/j158.java deleted file mode 100644 index 0d6b64e1..00000000 --- a/Java/j158.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - System.out.println(x ? "Positive" : "Negative"); - } -} diff --git a/Java/j159.java b/Java/j159.java deleted file mode 100644 index dbe4f37b..00000000 --- a/Java/j159.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = "123"; - int number = Integer.toInt(str); - System.out.println(number); - } -} diff --git a/Java/j16.java b/Java/j16.java deleted file mode 100644 index c7b34e94..00000000 --- a/Java/j16.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = 10; - System.out.println(a > b ? "Greater" : "Smaller"); - else System.out.println("Equal"); - } -} diff --git a/Java/j160.java b/Java/j160.java deleted file mode 100644 index 29166d2d..00000000 --- a/Java/j160.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - System.out.println(arr(0)); - } -} diff --git a/Java/j161.java b/Java/j161.java deleted file mode 100644 index 592c8748..00000000 --- a/Java/j161.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isTrue = false; - if (isTrue = true) { - System.out.println("True"); - } - } -} diff --git a/Java/j162.java b/Java/j162.java deleted file mode 100644 index 50147011..00000000 --- a/Java/j162.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - float b = 10.5; - int c = a + b; - System.out.println(c); - } -} diff --git a/Java/j163.java b/Java/j163.java deleted file mode 100644 index 7b4b85f0..00000000 --- a/Java/j163.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Hello"; - System.out.println(text.subString(1, 4)); - } -} diff --git a/Java/j164.java b/Java/j164.java deleted file mode 100644 index 59202072..00000000 --- a/Java/j164.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - arr.length(); - } -} diff --git a/Java/j165.java b/Java/j165.java deleted file mode 100644 index c6096f98..00000000 --- a/Java/j165.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a++ + ++a); - } -} diff --git a/Java/j166.java b/Java/j166.java deleted file mode 100644 index 110543be..00000000 --- a/Java/j166.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("Alice"); - System.out.println(list[0]); - } -} diff --git a/Java/j167.java b/Java/j167.java deleted file mode 100644 index 79f76aca..00000000 --- a/Java/j167.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "apple"; - text.charAt(5); - System.out.println(text); - } -} diff --git a/Java/j168.java b/Java/j168.java deleted file mode 100644 index 0fdc631e..00000000 --- a/Java/j168.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = 1 / 2; - System.out.println(value); - } -} diff --git a/Java/j169.java b/Java/j169.java deleted file mode 100644 index 4372f8ab..00000000 --- a/Java/j169.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(Arrays.toString(numbers)); - } -} diff --git a/Java/j17.java b/Java/j17.java deleted file mode 100644 index a6d9e74d..00000000 --- a/Java/j17.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int value = null; - System.out.println(value); - } -} diff --git a/Java/j170.java b/Java/j170.java deleted file mode 100644 index 6fe100df..00000000 --- a/Java/j170.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i++) { - System.out.println(i); - } - } -} diff --git a/Java/j171.java b/Java/j171.java deleted file mode 100644 index 21780bb5..00000000 --- a/Java/j171.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "John"; - System.out.println(name.indexOf()); - } -} diff --git a/Java/j172.java b/Java/j172.java deleted file mode 100644 index a85f7153..00000000 --- a/Java/j172.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - boolean b = (a = 10); - System.out.println(b); - } -} diff --git a/Java/j173.java b/Java/j173.java deleted file mode 100644 index 57e8a1b0..00000000 --- a/Java/j173.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = null; - System.out.println(text.isEmpty()); - } -} diff --git a/Java/j174.java b/Java/j174.java deleted file mode 100644 index 7b9b96d6..00000000 --- a/Java/j174.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String result = Integer.toInt(a); - System.out.println(result); - } -} diff --git a/Java/j175.java b/Java/j175.java deleted file mode 100644 index a72a9e5b..00000000 --- a/Java/j175.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println((double) x / 0); - } -} diff --git a/Java/j176.java b/Java/j176.java deleted file mode 100644 index e1549a3d..00000000 --- a/Java/j176.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - System.out.println(a instanceof Integer); - } -} diff --git a/Java/j177.java b/Java/j177.java deleted file mode 100644 index 23df4d81..00000000 --- a/Java/j177.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean flag = true; - if (flag = false) { - System.out.println("True"); - } - } -} diff --git a/Java/j178.java b/Java/j178.java deleted file mode 100644 index ff52a4d9..00000000 --- a/Java/j178.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = 100; - System.out.println(str); - } -} diff --git a/Java/j179.java b/Java/j179.java deleted file mode 100644 index ed2503fe..00000000 --- a/Java/j179.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("Hello"); - list.add(5); - } -} diff --git a/Java/j18.java b/Java/j18.java deleted file mode 100644 index 2f2cc5fe..00000000 --- a/Java/j18.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - Integer x = 1000; - if (x == 1000) { - System.out.println("Equal"); - } - } -} diff --git a/Java/j180.java b/Java/j180.java deleted file mode 100644 index ccad6126..00000000 --- a/Java/j180.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - String result = Integer.parseInt(x); - System.out.println(result); - } -} diff --git a/Java/j181.java b/Java/j181.java deleted file mode 100644 index 553c4d00..00000000 --- a/Java/j181.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(Math.pow(2)); - } -} diff --git a/Java/j182.java b/Java/j182.java deleted file mode 100644 index 4a090e80..00000000 --- a/Java/j182.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - text.replace("a", 'o'); - System.out.println(text); - } -} diff --git a/Java/j183.java b/Java/j183.java deleted file mode 100644 index 7a0e14bb..00000000 --- a/Java/j183.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"one", "two", "three"}; - for (String i = arr) { - System.out.println(i); - } - } -} diff --git a/Java/j184.java b/Java/j184.java deleted file mode 100644 index 365f7630..00000000 --- a/Java/j184.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "hello"; - text.charAt(10); - System.out.println(text); - } -} diff --git a/Java/j185.java b/Java/j185.java deleted file mode 100644 index 98f05d54..00000000 --- a/Java/j185.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String result = a.toString(); - System.out.println(result); - } -} diff --git a/Java/j186.java b/Java/j186.java deleted file mode 100644 index c2892352..00000000 --- a/Java/j186.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = 10; - System.out.println(a = b ? "Equal" : "Not Equal"); - } -} diff --git a/Java/j187.java b/Java/j187.java deleted file mode 100644 index c537eb1f..00000000 --- a/Java/j187.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] items = {"Apple", "Orange"}; - System.out.println(items[-1]); - } -} diff --git a/Java/j188.java b/Java/j188.java deleted file mode 100644 index 1d16164b..00000000 --- a/Java/j188.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i = 0; i < arr.size(); i++) { - System.out.println(arr[i]); - } - } -} diff --git a/Java/j189.java b/Java/j189.java deleted file mode 100644 index f72f5930..00000000 --- a/Java/j189.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - if (a > 10) - System.out.println("a is greater than 10"); - else - System.out.println("a is less than 10"); - System.out.println("This will always print"); - } -} diff --git a/Java/j19.java b/Java/j19.java deleted file mode 100644 index a48c579a..00000000 --- a/Java/j19.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr.add(10); - System.out.println(arr[0]); - } -} diff --git a/Java/j190.java b/Java/j190.java deleted file mode 100644 index d97ad27e..00000000 --- a/Java/j190.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.max(); - System.out.println(x); - } -} diff --git a/Java/j191.java b/Java/j191.java deleted file mode 100644 index 6996ccbb..00000000 --- a/Java/j191.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double b = 10.5; - System.out.println(a + (String) b); - } -} diff --git a/Java/j192.java b/Java/j192.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j192.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/j193.java b/Java/j193.java deleted file mode 100644 index 3c736152..00000000 --- a/Java/j193.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"A", "B", "C"}; - System.out.println(arr.length()); - } -} diff --git a/Java/j194.java b/Java/j194.java deleted file mode 100644 index 38890e5c..00000000 --- a/Java/j194.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[5]; - System.out.println(numbers.size()); - } -} diff --git a/Java/j195.java b/Java/j195.java deleted file mode 100644 index 8e600a52..00000000 --- a/Java/j195.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - System.out.println(numbers); - } -} diff --git a/Java/j196.java b/Java/j196.java deleted file mode 100644 index 3e08f39d..00000000 --- a/Java/j196.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello"; - message.concat("World"); - System.out.println(message); - } -} diff --git a/Java/j197.java b/Java/j197.java deleted file mode 100644 index fa75f2c2..00000000 --- a/Java/j197.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 100; - System.out.println(x ? "Yes" : "No"); - } -} diff --git a/Java/j198.java b/Java/j198.java deleted file mode 100644 index 512b4770..00000000 --- a/Java/j198.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = new int[5]; - nums.add(10); - System.out.println(nums[0]); - } -} diff --git a/Java/j199.java b/Java/j199.java deleted file mode 100644 index 691e4d52..00000000 --- a/Java/j199.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "abc"; - System.out.println(text.charAt(5)); - } -} diff --git a/Java/j2.java b/Java/j2.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j2.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j20.java b/Java/j20.java deleted file mode 100644 index effdaa79..00000000 --- a/Java/j20.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[-10]; - System.out.println(numbers.length); - } -} diff --git a/Java/j200.java b/Java/j200.java deleted file mode 100644 index 81d07e4f..00000000 --- a/Java/j200.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - double y = 0; - System.out.println(x / y); - } -} diff --git a/Java/j201.java b/Java/j201.java deleted file mode 100644 index 281ff6b5..00000000 --- a/Java/j201.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] fruits = new String[5]; - fruits[5] = "Apple"; - } -} diff --git a/Java/j202.java b/Java/j202.java deleted file mode 100644 index f5b3ed42..00000000 --- a/Java/j202.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean result = (5 == 5 ? "true" : "false"); - System.out.println(result); - } -} diff --git a/Java/j203.java b/Java/j203.java deleted file mode 100644 index e7bff523..00000000 --- a/Java/j203.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double b = 0; - int result = a / b; - System.out.println(result); - } -} diff --git a/Java/j204.java b/Java/j204.java deleted file mode 100644 index 19f1b1b0..00000000 --- a/Java/j204.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double result = Math.pow(2); - System.out.println(result); - } -} diff --git a/Java/j205.java b/Java/j205.java deleted file mode 100644 index 742cd3c0..00000000 --- a/Java/j205.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a + " " + Math.pow(a, 2)); - } -} diff --git a/Java/j206.java b/Java/j206.java deleted file mode 100644 index b3373a05..00000000 --- a/Java/j206.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List names = new ArrayList<>(); - names.add("Alice", "Bob"); - System.out.println(names); - } -} diff --git a/Java/j207.java b/Java/j207.java deleted file mode 100644 index 016b1f2e..00000000 --- a/Java/j207.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println("x is " x); - } -} diff --git a/Java/j208.java b/Java/j208.java deleted file mode 100644 index e50af3ed..00000000 --- a/Java/j208.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char ch = "Hello"; - System.out.println(ch); - } -} diff --git a/Java/j209.java b/Java/j209.java deleted file mode 100644 index 89b504c8..00000000 --- a/Java/j209.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[-5]; - System.out.println(arr.length); - } -} diff --git a/Java/j21.java b/Java/j21.java deleted file mode 100644 index 618ab414..00000000 --- a/Java/j21.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10, i++) { - System.out.println(i); - } - } -} diff --git a/Java/j210.java b/Java/j210.java deleted file mode 100644 index 0f51e68d..00000000 --- a/Java/j210.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = 3.14; - int x = value; - System.out.println(x); - } -} diff --git a/Java/j211.java b/Java/j211.java deleted file mode 100644 index ff9dc6f6..00000000 --- a/Java/j211.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - if (x == 5); - System.out.println("x is 5"); - } -} diff --git a/Java/j212.java b/Java/j212.java deleted file mode 100644 index 2afcec8c..00000000 --- a/Java/j212.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = "100"; - System.out.println(a); - } -} diff --git a/Java/j213.java b/Java/j213.java deleted file mode 100644 index c20f4564..00000000 --- a/Java/j213.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = new String[3]; - System.out.println(arr.size()); - } -} diff --git a/Java/j214.java b/Java/j214.java deleted file mode 100644 index 13e57a3b..00000000 --- a/Java/j214.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double b = 10.5; - int c = a + b; - System.out.println(c); - } -} diff --git a/Java/j215.java b/Java/j215.java deleted file mode 100644 index 3e91deef..00000000 --- a/Java/j215.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "abc"; - System.out.println(text.substring(4)); - } -} diff --git a/Java/j216.java b/Java/j216.java deleted file mode 100644 index 0f2aa86c..00000000 --- a/Java/j216.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = new String[] {"A", "B", "C"}; - System.out.println(arr.get(0)); - } -} diff --git a/Java/j217.java b/Java/j217.java deleted file mode 100644 index 76c9c803..00000000 --- a/Java/j217.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "hello"; - char ch = text.charAt(6); - System.out.println(ch); - } -} diff --git a/Java/j218.java b/Java/j218.java deleted file mode 100644 index 4e0091b2..00000000 --- a/Java/j218.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - double result = x / 0; - System.out.println(result); - } -} diff --git a/Java/j219.java b/Java/j219.java deleted file mode 100644 index 170540b5..00000000 --- a/Java/j219.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(Math.sqrt(-1)); - } -} diff --git a/Java/j22.java b/Java/j22.java deleted file mode 100644 index a279fb68..00000000 --- a/Java/j22.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr.size()); - } -} diff --git a/Java/j220.java b/Java/j220.java deleted file mode 100644 index 38fcf1b9..00000000 --- a/Java/j220.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 0; - System.out.println(x); - } -} diff --git a/Java/j221.java b/Java/j221.java deleted file mode 100644 index e883b0b7..00000000 --- a/Java/j221.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - arr[3] = 10; - } -} diff --git a/Java/j222.java b/Java/j222.java deleted file mode 100644 index f6b4e353..00000000 --- a/Java/j222.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = null; - System.out.println(name.isEmpty()); - } -} diff --git a/Java/j223.java b/Java/j223.java deleted file mode 100644 index 92f39cc0..00000000 --- a/Java/j223.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - text.toUppercase(); - System.out.println(text); - } -} diff --git a/Java/j224.java b/Java/j224.java deleted file mode 100644 index b8e95e0d..00000000 --- a/Java/j224.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - boolean result = (a = 10); - System.out.println(result); - } -} diff --git a/Java/j225.java b/Java/j225.java deleted file mode 100644 index eb3f86fb..00000000 --- a/Java/j225.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "Alice"; - char letter = name.charAt(10); - System.out.println(letter); - } -} diff --git a/Java/j226.java b/Java/j226.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j226.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/j227.java b/Java/j227.java deleted file mode 100644 index c81307bf..00000000 --- a/Java/j227.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = null; - System.out.println(x); - } -} diff --git a/Java/j228.java b/Java/j228.java deleted file mode 100644 index 9eb01975..00000000 --- a/Java/j228.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello World"; - System.out.println(message.charAt(11)); - } -} diff --git a/Java/j229.java b/Java/j229.java deleted file mode 100644 index 59202072..00000000 --- a/Java/j229.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - arr.length(); - } -} diff --git a/Java/j23.java b/Java/j23.java deleted file mode 100644 index 323126a4..00000000 --- a/Java/j23.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = "10"; - System.out.println(a); - } -} diff --git a/Java/j230.java b/Java/j230.java deleted file mode 100644 index 5e8221a7..00000000 --- a/Java/j230.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List fruits = new ArrayList<>(); - fruits.add("Apple"); - fruits(0) = "Banana"; - } -} diff --git a/Java/j231.java b/Java/j231.java deleted file mode 100644 index c6397e94..00000000 --- a/Java/j231.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - text.replace('a', "b"); - System.out.println(text); - } -} diff --git a/Java/j232.java b/Java/j232.java deleted file mode 100644 index 9148ad10..00000000 --- a/Java/j232.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = Math.sqrt(25); - int result = value; - System.out.println(result); - } -} diff --git a/Java/j233.java b/Java/j233.java deleted file mode 100644 index 6a188364..00000000 --- a/Java/j233.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - int result = a + b; - System.out.println(result); - } -} diff --git a/Java/j234.java b/Java/j234.java deleted file mode 100644 index 7fef1b77..00000000 --- a/Java/j234.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - System.out.println(s.charAt(4)); - } -} diff --git a/Java/j235.java b/Java/j235.java deleted file mode 100644 index e1cc0736..00000000 --- a/Java/j235.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x ? "Yes" : "No"); - } -} diff --git a/Java/j236.java b/Java/j236.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j236.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j237.java b/Java/j237.java deleted file mode 100644 index dfcdda03..00000000 --- a/Java/j237.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double result = Math.pow(5); - System.out.println(result); - } -} diff --git a/Java/j238.java b/Java/j238.java deleted file mode 100644 index 2c5342d4..00000000 --- a/Java/j238.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = null; - if (str.equals("Hello")) { - System.out.println("Hello"); - } - } -} diff --git a/Java/j239.java b/Java/j239.java deleted file mode 100644 index e1549a3d..00000000 --- a/Java/j239.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - System.out.println(a instanceof Integer); - } -} diff --git a/Java/j24.java b/Java/j24.java deleted file mode 100644 index 512b4770..00000000 --- a/Java/j24.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = new int[5]; - nums.add(10); - System.out.println(nums[0]); - } -} diff --git a/Java/j240.java b/Java/j240.java deleted file mode 100644 index 7c6ca477..00000000 --- a/Java/j240.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double num = 5 / 2; - System.out.println(num); - } -} diff --git a/Java/j241.java b/Java/j241.java deleted file mode 100644 index 37264826..00000000 --- a/Java/j241.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"A", "B", "C"}; - arr[3] = "D"; - } -} diff --git a/Java/j242.java b/Java/j242.java deleted file mode 100644 index 1dd31ae2..00000000 --- a/Java/j242.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]{1, 2, 3}; - System.out.println(arr[0]); - } -} diff --git a/Java/j243.java b/Java/j243.java deleted file mode 100644 index 0b244a81..00000000 --- a/Java/j243.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello, World!"; - System.out.println(message.substring(1, 20)); - } -} diff --git a/Java/j244.java b/Java/j244.java deleted file mode 100644 index 04d37169..00000000 --- a/Java/j244.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.abs(); - System.out.println(x); - } -} diff --git a/Java/j245.java b/Java/j245.java deleted file mode 100644 index 7b4b85f0..00000000 --- a/Java/j245.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Hello"; - System.out.println(text.subString(1, 4)); - } -} diff --git a/Java/j246.java b/Java/j246.java deleted file mode 100644 index b69cb5e5..00000000 --- a/Java/j246.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello"; - message.replace('e', "a"); - System.out.println(message); - } -} diff --git a/Java/j247.java b/Java/j247.java deleted file mode 100644 index c7b0ba76..00000000 --- a/Java/j247.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = null; - if (str.equals("Hello")) { - System.out.println("Text is Hello"); - } - } -} diff --git a/Java/j248.java b/Java/j248.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j248.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/j249.java b/Java/j249.java deleted file mode 100644 index 0d6b64e1..00000000 --- a/Java/j249.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - System.out.println(x ? "Positive" : "Negative"); - } -} diff --git a/Java/j25.java b/Java/j25.java deleted file mode 100644 index 4cac3959..00000000 --- a/Java/j25.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "John"; - name.toUpperCase; - System.out.println(name); - } -} diff --git a/Java/j250.java b/Java/j250.java deleted file mode 100644 index e1226d9d..00000000 --- a/Java/j250.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char c = "A"; - System.out.println(c); - } -} diff --git a/Java/j26.java b/Java/j26.java deleted file mode 100644 index 46fc41eb..00000000 --- a/Java/j26.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x.toString()); - } -} diff --git a/Java/j27.java b/Java/j27.java deleted file mode 100644 index 5fed2e72..00000000 --- a/Java/j27.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[5]; - for (int i = 0; i <= 5; i++) { - numbers[i] = i; - } - } -} diff --git a/Java/j28.java b/Java/j28.java deleted file mode 100644 index 3e7a2697..00000000 --- a/Java/j28.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr[0] = "100"; - System.out.println(arr[0]); - } -} diff --git a/Java/j29.java b/Java/j29.java deleted file mode 100644 index f95ecfa5..00000000 --- a/Java/j29.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = "5"; - System.out.println(a + b); - } -} diff --git a/Java/j3.java b/Java/j3.java deleted file mode 100644 index eaee4844..00000000 --- a/Java/j3.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name; - System.out.println(name); - } -} diff --git a/Java/j30.java b/Java/j30.java deleted file mode 100644 index e71267cb..00000000 --- a/Java/j30.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.sqrt(-1); - System.out.println(x); - } -} diff --git a/Java/j31.java b/Java/j31.java deleted file mode 100644 index 93b9c2da..00000000 --- a/Java/j31.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a++ * ++a); - } -} diff --git a/Java/j32.java b/Java/j32.java deleted file mode 100644 index 281f2ca2..00000000 --- a/Java/j32.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - Integer b = null; - System.out.println(a + b); - } -} diff --git a/Java/j33.java b/Java/j33.java deleted file mode 100644 index e2d9bbb5..00000000 --- a/Java/j33.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - System.out.println(s.reverse()); - } -} diff --git a/Java/j34.java b/Java/j34.java deleted file mode 100644 index 8df564ce..00000000 --- a/Java/j34.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int num = 5; - num.equals(5); - } -} diff --git a/Java/j35.java b/Java/j35.java deleted file mode 100644 index 6cb75edb..00000000 --- a/Java/j35.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = null; - System.out.println(name.length()); - } -} diff --git a/Java/j36.java b/Java/j36.java deleted file mode 100644 index 1f220432..00000000 --- a/Java/j36.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - System.out.println(arr.toString()); - } -} diff --git a/Java/j37.java b/Java/j37.java deleted file mode 100644 index a5bd38f2..00000000 --- a/Java/j37.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - a++; - System.out.println(++a++); - } -} diff --git a/Java/j38.java b/Java/j38.java deleted file mode 100644 index a120ebe6..00000000 --- a/Java/j38.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr(0)); - } -} diff --git a/Java/j39.java b/Java/j39.java deleted file mode 100644 index 17e810ca..00000000 --- a/Java/j39.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.pow(2, 3); - System.out.println(x); - } -} diff --git a/Java/j4.java b/Java/j4.java deleted file mode 100644 index 72a2b101..00000000 --- a/Java/j4.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List names = new ArrayList<>(); - names.add("Alice"); - System.out.println(names[0]); - } -} diff --git a/Java/j40.java b/Java/j40.java deleted file mode 100644 index 9ac71510..00000000 --- a/Java/j40.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = "100"; - System.out.println(x); - } -} diff --git a/Java/j41.java b/Java/j41.java deleted file mode 100644 index 04077b2d..00000000 --- a/Java/j41.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("apple"); - System.out.println(list[0]); - } -} diff --git a/Java/j42.java b/Java/j42.java deleted file mode 100644 index 553c4d00..00000000 --- a/Java/j42.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(Math.pow(2)); - } -} diff --git a/Java/j43.java b/Java/j43.java deleted file mode 100644 index e3f960ad..00000000 --- a/Java/j43.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - System.out.println(s.length(5)); - } -} diff --git a/Java/j44.java b/Java/j44.java deleted file mode 100644 index 4c4c37d7..00000000 --- a/Java/j44.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List items = new ArrayList<>(); - items.add("Item1"); - System.out.println(items(0)); - } -} diff --git a/Java/j45.java b/Java/j45.java deleted file mode 100644 index f9648642..00000000 --- a/Java/j45.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5.0 / 0; - System.out.println(x); - } -} diff --git a/Java/j46.java b/Java/j46.java deleted file mode 100644 index fef86177..00000000 --- a/Java/j46.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isTrue = True; - System.out.println(isTrue); - } -} diff --git a/Java/j47.java b/Java/j47.java deleted file mode 100644 index ee629d44..00000000 --- a/Java/j47.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int result = Math.pow(a); - System.out.println(result); - } -} diff --git a/Java/j48.java b/Java/j48.java deleted file mode 100644 index 8efcdd08..00000000 --- a/Java/j48.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5 / 0; - System.out.println(x); - } -} diff --git a/Java/j49.java b/Java/j49.java deleted file mode 100644 index 7541cfb5..00000000 --- a/Java/j49.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - numbers.add(10); - System.out.println(numbers.get(0)); - } -} diff --git a/Java/j5.java b/Java/j5.java deleted file mode 100644 index f23bd213..00000000 --- a/Java/j5.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - System.out.println(arr); - } -} diff --git a/Java/j50.java b/Java/j50.java deleted file mode 100644 index 94e60da2..00000000 --- a/Java/j50.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "Java"; - System.out.println(name.indexOf(2)); - } -} diff --git a/Java/j51.java b/Java/j51.java deleted file mode 100644 index 79e32c7c..00000000 --- a/Java/j51.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int number = 5; - if (number = 5) { - System.out.println("Number is 5"); - } - } -} diff --git a/Java/j52.java b/Java/j52.java deleted file mode 100644 index 9da5b660..00000000 --- a/Java/j52.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - String s = 'Hello'; - } -} diff --git a/Java/j53.java b/Java/j53.java deleted file mode 100644 index f8e9057a..00000000 --- a/Java/j53.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr[5] = 10; - } -} diff --git a/Java/j54.java b/Java/j54.java deleted file mode 100644 index a3b4bdb7..00000000 --- a/Java/j54.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10 i++) { - System.out.println(i); - } - } -} diff --git a/Java/j55.java b/Java/j55.java deleted file mode 100644 index 2ec2adee..00000000 --- a/Java/j55.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String greeting = Hello; - System.out.println(greeting); - } -} diff --git a/Java/j56.java b/Java/j56.java deleted file mode 100644 index b26a30ef..00000000 --- a/Java/j56.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 1; - double y = x / 0; - System.out.println(y); - } -} diff --git a/Java/j57.java b/Java/j57.java deleted file mode 100644 index 2ec2adee..00000000 --- a/Java/j57.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String greeting = Hello; - System.out.println(greeting); - } -} diff --git a/Java/j58.java b/Java/j58.java deleted file mode 100644 index ba2a4989..00000000 --- a/Java/j58.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello, World!"; - char c = message.charAt(20); - System.out.println(c); - } -} diff --git a/Java/j59.java b/Java/j59.java deleted file mode 100644 index 7ebdbe61..00000000 --- a/Java/j59.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] fruits = {"Apple", "Banana", "Mango"}; - System.out.println(fruits[-1]); - } -} diff --git a/Java/j6.java b/Java/j6.java deleted file mode 100644 index d2f4d7a0..00000000 --- a/Java/j6.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "abc"; - System.out.println(s.charAt(5)); - } -} diff --git a/Java/j60.java b/Java/j60.java deleted file mode 100644 index cd25b0ca..00000000 --- a/Java/j60.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10, b = 0; - int result = a / b; - System.out.println(result); - } -} diff --git a/Java/j61.java b/Java/j61.java deleted file mode 100644 index d5df4b28..00000000 --- a/Java/j61.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i : arr) { - arr[i] = i * 2; - } - } -} diff --git a/Java/j62.java b/Java/j62.java deleted file mode 100644 index 791e7117..00000000 --- a/Java/j62.java +++ /dev/null @@ -1,9 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - while x > 0 { - System.out.println(x); - x--; - } - } -} diff --git a/Java/j63.java b/Java/j63.java deleted file mode 100644 index 510643e3..00000000 --- a/Java/j63.java +++ /dev/null @@ -1,11 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - switch (x) { - case 5: - System.out.println("Five"); - default: - System.out.println("Default case"); - } - } -} diff --git a/Java/j64.java b/Java/j64.java deleted file mode 100644 index 08ac285f..00000000 --- a/Java/j64.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[10]; - System.out.println(arr.length()); - } -} diff --git a/Java/j65.java b/Java/j65.java deleted file mode 100644 index 5133658e..00000000 --- a/Java/j65.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - double pi = 3.14159; - double radius = 5.0; - double area = Math.pi * radius * radius; - System.out.println(area); - } -} diff --git a/Java/j66.java b/Java/j66.java deleted file mode 100644 index 04e67736..00000000 --- a/Java/j66.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = '10'; - System.out.println(a + b); - } -} diff --git a/Java/j67.java b/Java/j67.java deleted file mode 100644 index 1f4dfd2c..00000000 --- a/Java/j67.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = null; - System.out.println(str.length()); - } -} diff --git a/Java/j68.java b/Java/j68.java deleted file mode 100644 index 1fee6d93..00000000 --- a/Java/j68.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char ch = "A"; - System.out.println(ch); - } -} diff --git a/Java/j69.java b/Java/j69.java deleted file mode 100644 index 2410b07f..00000000 --- a/Java/j69.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x.equals(10)); - } -} diff --git a/Java/j7.java b/Java/j7.java deleted file mode 100644 index ab976e15..00000000 --- a/Java/j7.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = new int[-5]; - System.out.println(nums.length); - } -} diff --git a/Java/j70.java b/Java/j70.java deleted file mode 100644 index 0761fafe..00000000 --- a/Java/j70.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - s.toUppercase(); - System.out.println(s); - } -} diff --git a/Java/j71.java b/Java/j71.java deleted file mode 100644 index 92f65700..00000000 --- a/Java/j71.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int result = 5 + ; - System.out.println(result); - } -} diff --git a/Java/j72.java b/Java/j72.java deleted file mode 100644 index cd802d95..00000000 --- a/Java/j72.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] names = {"John", "Doe"}; - for (int i = 0; i < names.size(); i++) { - System.out.println(names[i]); - } - } -} diff --git a/Java/j73.java b/Java/j73.java deleted file mode 100644 index 749cd12f..00000000 --- a/Java/j73.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - double y = 0.0; - double result = x % y; - System.out.println(result); - } -} diff --git a/Java/j74.java b/Java/j74.java deleted file mode 100644 index 81d69ba2..00000000 --- a/Java/j74.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 100; - byte b = a; - System.out.println(b); - } -} diff --git a/Java/j75.java b/Java/j75.java deleted file mode 100644 index 330bab44..00000000 --- a/Java/j75.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - int c = b + a; - System.out.println(c); - } -} diff --git a/Java/j76.java b/Java/j76.java deleted file mode 100644 index 76303a87..00000000 --- a/Java/j76.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10; i++); - System.out.println(i); - } -} diff --git a/Java/j77.java b/Java/j77.java deleted file mode 100644 index e71267cb..00000000 --- a/Java/j77.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.sqrt(-1); - System.out.println(x); - } -} diff --git a/Java/j78.java b/Java/j78.java deleted file mode 100644 index ae5b523a..00000000 --- a/Java/j78.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - Object obj = "Hello"; - int num = (int) obj; - System.out.println(num); - } -} diff --git a/Java/j79.java b/Java/j79.java deleted file mode 100644 index 323126a4..00000000 --- a/Java/j79.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = "10"; - System.out.println(a); - } -} diff --git a/Java/j8.java b/Java/j8.java deleted file mode 100644 index 0e12d9b4..00000000 --- a/Java/j8.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double result = Math.pow(a); - System.out.println(result); - } -} diff --git a/Java/j80.java b/Java/j80.java deleted file mode 100644 index 00792c77..00000000 --- a/Java/j80.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - a++; - System.out.println(a++); - } -} diff --git a/Java/j81.java b/Java/j81.java deleted file mode 100644 index e2299c31..00000000 --- a/Java/j81.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - s = null; - System.out.println(s.toUpperCase()); - } -} diff --git a/Java/j82.java b/Java/j82.java deleted file mode 100644 index fee97c52..00000000 --- a/Java/j82.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String s = Integer.parseInt(a); - System.out.println(s); - } -} diff --git a/Java/j83.java b/Java/j83.java deleted file mode 100644 index 56eb400e..00000000 --- a/Java/j83.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - s.replace('a', "o"); - System.out.println(s); - } -} diff --git a/Java/j84.java b/Java/j84.java deleted file mode 100644 index d7c341b2..00000000 --- a/Java/j84.java +++ /dev/null @@ -1,9 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 0; - while (a = 10) { - System.out.println(a); - a++; - } - } -} diff --git a/Java/j85.java b/Java/j85.java deleted file mode 100644 index 8fda5992..00000000 --- a/Java/j85.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] fruits = new String[]{"Apple", "Orange", "Banana"}; - System.out.println(fruits(0)); - } -} diff --git a/Java/j86.java b/Java/j86.java deleted file mode 100644 index 8a081f5b..00000000 --- a/Java/j86.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 1; - do { - System.out.println(a); - } while a < 10; - } -} diff --git a/Java/j87.java b/Java/j87.java deleted file mode 100644 index d95036c3..00000000 --- a/Java/j87.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = 'Hello World'; - System.out.println(message); - } -} diff --git a/Java/j88.java b/Java/j88.java deleted file mode 100644 index e682fd89..00000000 --- a/Java/j88.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println("Sum of 5 and 10 is: " + 5 + 10); - } -} diff --git a/Java/j89.java b/Java/j89.java deleted file mode 100644 index d9c21db8..00000000 --- a/Java/j89.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = {1, 2, 3}; - System.out.println(nums[-1]); - } -} diff --git a/Java/j9.java b/Java/j9.java deleted file mode 100644 index 5916015d..00000000 --- a/Java/j9.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[3]; - numbers[0] = 5; - numbers[3] = 10; - } -} diff --git a/Java/j90.java b/Java/j90.java deleted file mode 100644 index b895ac41..00000000 --- a/Java/j90.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr.length()); - } -} diff --git a/Java/j91.java b/Java/j91.java deleted file mode 100644 index 1dd31ae2..00000000 --- a/Java/j91.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]{1, 2, 3}; - System.out.println(arr[0]); - } -} diff --git a/Java/j92.java b/Java/j92.java deleted file mode 100644 index d189b35e..00000000 --- a/Java/j92.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = 10.5; - int result = value + 5; - System.out.println(result); - } -} diff --git a/Java/j93.java b/Java/j93.java deleted file mode 100644 index bfb9a4c3..00000000 --- a/Java/j93.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = null; - if (text.equals("Hello")) { - System.out.println("Text is Hello"); - } - } -} diff --git a/Java/j94.java b/Java/j94.java deleted file mode 100644 index f01163e5..00000000 --- a/Java/j94.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String result = 5 + 10; - System.out.println(result); - } -} diff --git a/Java/j95.java b/Java/j95.java deleted file mode 100644 index c2d6467a..00000000 --- a/Java/j95.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char c = 'Hello'; - System.out.println(c); - } -} diff --git a/Java/j96.java b/Java/j96.java deleted file mode 100644 index 076bbfad..00000000 --- a/Java/j96.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int i = 10; - System.out.println(++i++); - } -} diff --git a/Java/j97.java b/Java/j97.java deleted file mode 100644 index dd542d87..00000000 --- a/Java/j97.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - final int a = 5; - a = 10; - System.out.println(a); - } -} diff --git a/Java/j98.java b/Java/j98.java deleted file mode 100644 index a48c579a..00000000 --- a/Java/j98.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr.add(10); - System.out.println(arr[0]); - } -} diff --git a/Java/j99.java b/Java/j99.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j99.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/temp.txt b/Java/temp.txt deleted file mode 100644 index 5d72a670..00000000 --- a/Java/temp.txt +++ /dev/null @@ -1 +0,0 @@ -"." From 55d3f29fc1d967320b6793f7a17490dacc449ad8 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:43:48 +0530 Subject: [PATCH 19/62] Create temp.txt --- Java/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Java/temp.txt diff --git a/Java/temp.txt b/Java/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/temp.txt @@ -0,0 +1 @@ + From 9218777d97b7b7e9dd7692e0c31974e82406f56e Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:44:40 +0530 Subject: [PATCH 20/62] Create temp.txt --- Java/Easy/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Java/Easy/temp.txt diff --git a/Java/Easy/temp.txt b/Java/Easy/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/Easy/temp.txt @@ -0,0 +1 @@ + From 0a052b3f21225d9b18af935f213822e2eb3be465 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:44:54 +0530 Subject: [PATCH 21/62] Create temp.txt --- Java/Medium/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Java/Medium/temp.txt diff --git a/Java/Medium/temp.txt b/Java/Medium/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/Medium/temp.txt @@ -0,0 +1 @@ + From c7f61431b1d7050c968e1f85e294debeb9a13602 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:45:10 +0530 Subject: [PATCH 22/62] Create temp.txt --- Java/Hard/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Java/Hard/temp.txt diff --git a/Java/Hard/temp.txt b/Java/Hard/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/Hard/temp.txt @@ -0,0 +1 @@ + From bfaeb84a5f2e3150e8645067cfe0f16598ce31ee Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:55:50 +0530 Subject: [PATCH 23/62] java easy uploaded --- Java/Easy/167.java | 7 +++++++ Java/Easy/168.java | 6 ++++++ Java/Easy/169.java | 6 ++++++ Java/Easy/170.java | 7 +++++++ Java/Easy/171.java | 6 ++++++ Java/Easy/172.java | 7 +++++++ Java/Easy/173.java | 6 ++++++ Java/Easy/174.java | 7 +++++++ Java/Easy/175.java | 6 ++++++ Java/Easy/176.java | 6 ++++++ Java/Easy/177.java | 8 ++++++++ Java/Easy/178.java | 6 ++++++ Java/Easy/179.java | 7 +++++++ Java/Easy/180.java | 7 +++++++ Java/Easy/181.java | 5 +++++ Java/Easy/182.java | 7 +++++++ Java/Easy/183.java | 8 ++++++++ Java/Easy/184.java | 7 +++++++ Java/Easy/185.java | 7 +++++++ Java/Easy/186.java | 7 +++++++ Java/Easy/187.java | 6 ++++++ Java/Easy/188.java | 8 ++++++++ Java/Easy/189.java | 10 ++++++++++ Java/Easy/190.java | 6 ++++++ Java/Easy/191.java | 7 +++++++ Java/Easy/192.java | 6 ++++++ Java/Easy/193.java | 6 ++++++ Java/Easy/194.java | 6 ++++++ Java/Easy/195.java | 6 ++++++ Java/Easy/196.java | 7 +++++++ Java/Easy/197.java | 6 ++++++ Java/Easy/198.java | 7 +++++++ Java/Easy/199.java | 6 ++++++ Java/Easy/200.java | 7 +++++++ Java/Easy/201.java | 6 ++++++ Java/Easy/202.java | 6 ++++++ Java/Easy/203.java | 8 ++++++++ Java/Easy/204.java | 6 ++++++ Java/Easy/205.java | 6 ++++++ Java/Easy/206.java | 7 +++++++ Java/Easy/207.java | 6 ++++++ Java/Easy/208.java | 6 ++++++ Java/Easy/209.java | 6 ++++++ Java/Easy/210.java | 7 +++++++ Java/Easy/211.java | 7 +++++++ Java/Easy/212.java | 6 ++++++ Java/Easy/213.java | 6 ++++++ Java/Easy/214.java | 8 ++++++++ Java/Easy/215.java | 6 ++++++ Java/Easy/216.java | 6 ++++++ Java/Easy/217.java | 7 +++++++ Java/Easy/218.java | 7 +++++++ Java/Easy/219.java | 5 +++++ Java/Easy/220.java | 6 ++++++ Java/Easy/221.java | 6 ++++++ Java/Easy/222.java | 6 ++++++ Java/Easy/223.java | 7 +++++++ Java/Easy/224.java | 7 +++++++ Java/Easy/225.java | 7 +++++++ Java/Easy/226.java | 6 ++++++ Java/Easy/227.java | 6 ++++++ Java/Easy/228.java | 6 ++++++ Java/Easy/229.java | 6 ++++++ Java/Easy/230.java | 7 +++++++ Java/Easy/231.java | 7 +++++++ Java/Easy/232.java | 7 +++++++ Java/Easy/233.java | 8 ++++++++ Java/Easy/234.java | 6 ++++++ Java/Easy/235.java | 6 ++++++ Java/Easy/236.java | 6 ++++++ Java/Easy/237.java | 6 ++++++ Java/Easy/238.java | 8 ++++++++ Java/Easy/239.java | 6 ++++++ Java/Easy/240.java | 6 ++++++ Java/Easy/241.java | 6 ++++++ Java/Easy/242.java | 6 ++++++ Java/Easy/243.java | 6 ++++++ Java/Easy/244.java | 6 ++++++ Java/Easy/245.java | 6 ++++++ Java/Easy/246.java | 7 +++++++ Java/Easy/247.java | 8 ++++++++ Java/Easy/248.java | 6 ++++++ Java/Easy/249.java | 6 ++++++ Java/Easy/250.java | 6 ++++++ Java/Easy/91.java | 6 ++++++ 85 files changed, 554 insertions(+) create mode 100644 Java/Easy/167.java create mode 100644 Java/Easy/168.java create mode 100644 Java/Easy/169.java create mode 100644 Java/Easy/170.java create mode 100644 Java/Easy/171.java create mode 100644 Java/Easy/172.java create mode 100644 Java/Easy/173.java create mode 100644 Java/Easy/174.java create mode 100644 Java/Easy/175.java create mode 100644 Java/Easy/176.java create mode 100644 Java/Easy/177.java create mode 100644 Java/Easy/178.java create mode 100644 Java/Easy/179.java create mode 100644 Java/Easy/180.java create mode 100644 Java/Easy/181.java create mode 100644 Java/Easy/182.java create mode 100644 Java/Easy/183.java create mode 100644 Java/Easy/184.java create mode 100644 Java/Easy/185.java create mode 100644 Java/Easy/186.java create mode 100644 Java/Easy/187.java create mode 100644 Java/Easy/188.java create mode 100644 Java/Easy/189.java create mode 100644 Java/Easy/190.java create mode 100644 Java/Easy/191.java create mode 100644 Java/Easy/192.java create mode 100644 Java/Easy/193.java create mode 100644 Java/Easy/194.java create mode 100644 Java/Easy/195.java create mode 100644 Java/Easy/196.java create mode 100644 Java/Easy/197.java create mode 100644 Java/Easy/198.java create mode 100644 Java/Easy/199.java create mode 100644 Java/Easy/200.java create mode 100644 Java/Easy/201.java create mode 100644 Java/Easy/202.java create mode 100644 Java/Easy/203.java create mode 100644 Java/Easy/204.java create mode 100644 Java/Easy/205.java create mode 100644 Java/Easy/206.java create mode 100644 Java/Easy/207.java create mode 100644 Java/Easy/208.java create mode 100644 Java/Easy/209.java create mode 100644 Java/Easy/210.java create mode 100644 Java/Easy/211.java create mode 100644 Java/Easy/212.java create mode 100644 Java/Easy/213.java create mode 100644 Java/Easy/214.java create mode 100644 Java/Easy/215.java create mode 100644 Java/Easy/216.java create mode 100644 Java/Easy/217.java create mode 100644 Java/Easy/218.java create mode 100644 Java/Easy/219.java create mode 100644 Java/Easy/220.java create mode 100644 Java/Easy/221.java create mode 100644 Java/Easy/222.java create mode 100644 Java/Easy/223.java create mode 100644 Java/Easy/224.java create mode 100644 Java/Easy/225.java create mode 100644 Java/Easy/226.java create mode 100644 Java/Easy/227.java create mode 100644 Java/Easy/228.java create mode 100644 Java/Easy/229.java create mode 100644 Java/Easy/230.java create mode 100644 Java/Easy/231.java create mode 100644 Java/Easy/232.java create mode 100644 Java/Easy/233.java create mode 100644 Java/Easy/234.java create mode 100644 Java/Easy/235.java create mode 100644 Java/Easy/236.java create mode 100644 Java/Easy/237.java create mode 100644 Java/Easy/238.java create mode 100644 Java/Easy/239.java create mode 100644 Java/Easy/240.java create mode 100644 Java/Easy/241.java create mode 100644 Java/Easy/242.java create mode 100644 Java/Easy/243.java create mode 100644 Java/Easy/244.java create mode 100644 Java/Easy/245.java create mode 100644 Java/Easy/246.java create mode 100644 Java/Easy/247.java create mode 100644 Java/Easy/248.java create mode 100644 Java/Easy/249.java create mode 100644 Java/Easy/250.java create mode 100644 Java/Easy/91.java diff --git a/Java/Easy/167.java b/Java/Easy/167.java new file mode 100644 index 00000000..290a780e --- /dev/null +++ b/Java/Easy/167.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "apple"; + text.charAt(5); + System.out.println(text); + } +} diff --git a/Java/Easy/168.java b/Java/Easy/168.java new file mode 100644 index 00000000..86048e86 --- /dev/null +++ b/Java/Easy/168.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double value = 1 / 2; + System.out.println(value); + } +} diff --git a/Java/Easy/169.java b/Java/Easy/169.java new file mode 100644 index 00000000..2fd4c142 --- /dev/null +++ b/Java/Easy/169.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(Arrays.toString(numbers)); + } +} diff --git a/Java/Easy/170.java b/Java/Easy/170.java new file mode 100644 index 00000000..a423f378 --- /dev/null +++ b/Java/Easy/170.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/171.java b/Java/Easy/171.java new file mode 100644 index 00000000..06724785 --- /dev/null +++ b/Java/Easy/171.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = "John"; + System.out.println(name.indexOf()); + } +} diff --git a/Java/Easy/172.java b/Java/Easy/172.java new file mode 100644 index 00000000..7defb279 --- /dev/null +++ b/Java/Easy/172.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + boolean b = (a = 10); + System.out.println(b); + } +} diff --git a/Java/Easy/173.java b/Java/Easy/173.java new file mode 100644 index 00000000..4e1e7f2b --- /dev/null +++ b/Java/Easy/173.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = null; + System.out.println(text.isEmpty()); + } +} diff --git a/Java/Easy/174.java b/Java/Easy/174.java new file mode 100644 index 00000000..185367f3 --- /dev/null +++ b/Java/Easy/174.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String result = Integer.toInt(a); + System.out.println(result); + } +} diff --git a/Java/Easy/175.java b/Java/Easy/175.java new file mode 100644 index 00000000..6377408b --- /dev/null +++ b/Java/Easy/175.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println((double) x / 0); + } +} diff --git a/Java/Easy/176.java b/Java/Easy/176.java new file mode 100644 index 00000000..80527d07 --- /dev/null +++ b/Java/Easy/176.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 10; + System.out.println(a instanceof Integer); + } +} diff --git a/Java/Easy/177.java b/Java/Easy/177.java new file mode 100644 index 00000000..883668f1 --- /dev/null +++ b/Java/Easy/177.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + boolean flag = true; + if (flag = false) { + System.out.println("True"); + } + } +} diff --git a/Java/Easy/178.java b/Java/Easy/178.java new file mode 100644 index 00000000..88c65db6 --- /dev/null +++ b/Java/Easy/178.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String str = 100; + System.out.println(str); + } +} diff --git a/Java/Easy/179.java b/Java/Easy/179.java new file mode 100644 index 00000000..229f7721 --- /dev/null +++ b/Java/Easy/179.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Hello"); + list.add(5); + } +} diff --git a/Java/Easy/180.java b/Java/Easy/180.java new file mode 100644 index 00000000..a12070e0 --- /dev/null +++ b/Java/Easy/180.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 5; + String result = Integer.parseInt(x); + System.out.println(result); + } +} diff --git a/Java/Easy/181.java b/Java/Easy/181.java new file mode 100644 index 00000000..248a6787 --- /dev/null +++ b/Java/Easy/181.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(Math.pow(2)); + } +} diff --git a/Java/Easy/182.java b/Java/Easy/182.java new file mode 100644 index 00000000..7ed2dc10 --- /dev/null +++ b/Java/Easy/182.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + text.replace("a", 'o'); + System.out.println(text); + } +} diff --git a/Java/Easy/183.java b/Java/Easy/183.java new file mode 100644 index 00000000..6328d1b9 --- /dev/null +++ b/Java/Easy/183.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"one", "two", "three"}; + for (String i = arr) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/184.java b/Java/Easy/184.java new file mode 100644 index 00000000..cbcae932 --- /dev/null +++ b/Java/Easy/184.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "hello"; + text.charAt(10); + System.out.println(text); + } +} diff --git a/Java/Easy/185.java b/Java/Easy/185.java new file mode 100644 index 00000000..32b60a0b --- /dev/null +++ b/Java/Easy/185.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String result = a.toString(); + System.out.println(result); + } +} diff --git a/Java/Easy/186.java b/Java/Easy/186.java new file mode 100644 index 00000000..0b2ed84c --- /dev/null +++ b/Java/Easy/186.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = 10; + System.out.println(a = b ? "Equal" : "Not Equal"); + } +} diff --git a/Java/Easy/187.java b/Java/Easy/187.java new file mode 100644 index 00000000..9990364d --- /dev/null +++ b/Java/Easy/187.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] items = {"Apple", "Orange"}; + System.out.println(items[-1]); + } +} diff --git a/Java/Easy/188.java b/Java/Easy/188.java new file mode 100644 index 00000000..f9b87949 --- /dev/null +++ b/Java/Easy/188.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i = 0; i < arr.size(); i++) { + System.out.println(arr[i]); + } + } +} diff --git a/Java/Easy/189.java b/Java/Easy/189.java new file mode 100644 index 00000000..74424378 --- /dev/null +++ b/Java/Easy/189.java @@ -0,0 +1,10 @@ +class Main { + public static void main(String[] args) { + int a = 5; + if (a > 10) + System.out.println("a is greater than 10"); + else + System.out.println("a is less than 10"); + System.out.println("This will always print"); + } +} diff --git a/Java/Easy/190.java b/Java/Easy/190.java new file mode 100644 index 00000000..ce08592f --- /dev/null +++ b/Java/Easy/190.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.max(); + System.out.println(x); + } +} diff --git a/Java/Easy/191.java b/Java/Easy/191.java new file mode 100644 index 00000000..4d3d77be --- /dev/null +++ b/Java/Easy/191.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double b = 10.5; + System.out.println(a + (String) b); + } +} diff --git a/Java/Easy/192.java b/Java/Easy/192.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/192.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/193.java b/Java/Easy/193.java new file mode 100644 index 00000000..7f497598 --- /dev/null +++ b/Java/Easy/193.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"A", "B", "C"}; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/194.java b/Java/Easy/194.java new file mode 100644 index 00000000..899711c3 --- /dev/null +++ b/Java/Easy/194.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[5]; + System.out.println(numbers.size()); + } +} diff --git a/Java/Easy/195.java b/Java/Easy/195.java new file mode 100644 index 00000000..968222f0 --- /dev/null +++ b/Java/Easy/195.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + System.out.println(numbers); + } +} diff --git a/Java/Easy/196.java b/Java/Easy/196.java new file mode 100644 index 00000000..aac002c5 --- /dev/null +++ b/Java/Easy/196.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String message = "Hello"; + message.concat("World"); + System.out.println(message); + } +} diff --git a/Java/Easy/197.java b/Java/Easy/197.java new file mode 100644 index 00000000..0cd4ebb1 --- /dev/null +++ b/Java/Easy/197.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 100; + System.out.println(x ? "Yes" : "No"); + } +} diff --git a/Java/Easy/198.java b/Java/Easy/198.java new file mode 100644 index 00000000..13bc35b2 --- /dev/null +++ b/Java/Easy/198.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] nums = new int[5]; + nums.add(10); + System.out.println(nums[0]); + } +} diff --git a/Java/Easy/199.java b/Java/Easy/199.java new file mode 100644 index 00000000..1acc4da3 --- /dev/null +++ b/Java/Easy/199.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "abc"; + System.out.println(text.charAt(5)); + } +} diff --git a/Java/Easy/200.java b/Java/Easy/200.java new file mode 100644 index 00000000..e516a5ff --- /dev/null +++ b/Java/Easy/200.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 10; + double y = 0; + System.out.println(x / y); + } +} diff --git a/Java/Easy/201.java b/Java/Easy/201.java new file mode 100644 index 00000000..dcaf2e6c --- /dev/null +++ b/Java/Easy/201.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] fruits = new String[5]; + fruits[5] = "Apple"; + } +} diff --git a/Java/Easy/202.java b/Java/Easy/202.java new file mode 100644 index 00000000..e6b16815 --- /dev/null +++ b/Java/Easy/202.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean result = (5 == 5 ? "true" : "false"); + System.out.println(result); + } +} diff --git a/Java/Easy/203.java b/Java/Easy/203.java new file mode 100644 index 00000000..8f08c3a7 --- /dev/null +++ b/Java/Easy/203.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double b = 0; + int result = a / b; + System.out.println(result); + } +} diff --git a/Java/Easy/204.java b/Java/Easy/204.java new file mode 100644 index 00000000..5575f531 --- /dev/null +++ b/Java/Easy/204.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double result = Math.pow(2); + System.out.println(result); + } +} diff --git a/Java/Easy/205.java b/Java/Easy/205.java new file mode 100644 index 00000000..c01de6f0 --- /dev/null +++ b/Java/Easy/205.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a + " " + Math.pow(a, 2)); + } +} diff --git a/Java/Easy/206.java b/Java/Easy/206.java new file mode 100644 index 00000000..1b0182c3 --- /dev/null +++ b/Java/Easy/206.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List names = new ArrayList<>(); + names.add("Alice", "Bob"); + System.out.println(names); + } +} diff --git a/Java/Easy/207.java b/Java/Easy/207.java new file mode 100644 index 00000000..bb94d139 --- /dev/null +++ b/Java/Easy/207.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println("x is " x); + } +} diff --git a/Java/Easy/208.java b/Java/Easy/208.java new file mode 100644 index 00000000..20c6988a --- /dev/null +++ b/Java/Easy/208.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char ch = "Hello"; + System.out.println(ch); + } +} diff --git a/Java/Easy/209.java b/Java/Easy/209.java new file mode 100644 index 00000000..465361ab --- /dev/null +++ b/Java/Easy/209.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[-5]; + System.out.println(arr.length); + } +} diff --git a/Java/Easy/210.java b/Java/Easy/210.java new file mode 100644 index 00000000..d671e65c --- /dev/null +++ b/Java/Easy/210.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double value = 3.14; + int x = value; + System.out.println(x); + } +} diff --git a/Java/Easy/211.java b/Java/Easy/211.java new file mode 100644 index 00000000..f7f8f9a2 --- /dev/null +++ b/Java/Easy/211.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 5; + if (x == 5); + System.out.println("x is 5"); + } +} diff --git a/Java/Easy/212.java b/Java/Easy/212.java new file mode 100644 index 00000000..90c5f0b8 --- /dev/null +++ b/Java/Easy/212.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = "100"; + System.out.println(a); + } +} diff --git a/Java/Easy/213.java b/Java/Easy/213.java new file mode 100644 index 00000000..bdcc1f81 --- /dev/null +++ b/Java/Easy/213.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = new String[3]; + System.out.println(arr.size()); + } +} diff --git a/Java/Easy/214.java b/Java/Easy/214.java new file mode 100644 index 00000000..e1f0b6cc --- /dev/null +++ b/Java/Easy/214.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double b = 10.5; + int c = a + b; + System.out.println(c); + } +} diff --git a/Java/Easy/215.java b/Java/Easy/215.java new file mode 100644 index 00000000..97199118 --- /dev/null +++ b/Java/Easy/215.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "abc"; + System.out.println(text.substring(4)); + } +} diff --git a/Java/Easy/216.java b/Java/Easy/216.java new file mode 100644 index 00000000..f18ab67b --- /dev/null +++ b/Java/Easy/216.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = new String[] {"A", "B", "C"}; + System.out.println(arr.get(0)); + } +} diff --git a/Java/Easy/217.java b/Java/Easy/217.java new file mode 100644 index 00000000..9cb16a06 --- /dev/null +++ b/Java/Easy/217.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "hello"; + char ch = text.charAt(6); + System.out.println(ch); + } +} diff --git a/Java/Easy/218.java b/Java/Easy/218.java new file mode 100644 index 00000000..1d4e2b15 --- /dev/null +++ b/Java/Easy/218.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 5; + double result = x / 0; + System.out.println(result); + } +} diff --git a/Java/Easy/219.java b/Java/Easy/219.java new file mode 100644 index 00000000..1c89aa9f --- /dev/null +++ b/Java/Easy/219.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(Math.sqrt(-1)); + } +} diff --git a/Java/Easy/220.java b/Java/Easy/220.java new file mode 100644 index 00000000..7d8bbe77 --- /dev/null +++ b/Java/Easy/220.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/221.java b/Java/Easy/221.java new file mode 100644 index 00000000..b5b159a6 --- /dev/null +++ b/Java/Easy/221.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + arr[3] = 10; + } +} diff --git a/Java/Easy/222.java b/Java/Easy/222.java new file mode 100644 index 00000000..79c1713b --- /dev/null +++ b/Java/Easy/222.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = null; + System.out.println(name.isEmpty()); + } +} diff --git a/Java/Easy/223.java b/Java/Easy/223.java new file mode 100644 index 00000000..0b82455c --- /dev/null +++ b/Java/Easy/223.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + text.toUppercase(); + System.out.println(text); + } +} diff --git a/Java/Easy/224.java b/Java/Easy/224.java new file mode 100644 index 00000000..94896f15 --- /dev/null +++ b/Java/Easy/224.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + boolean result = (a = 10); + System.out.println(result); + } +} diff --git a/Java/Easy/225.java b/Java/Easy/225.java new file mode 100644 index 00000000..4c3c7c80 --- /dev/null +++ b/Java/Easy/225.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "Alice"; + char letter = name.charAt(10); + System.out.println(letter); + } +} diff --git a/Java/Easy/226.java b/Java/Easy/226.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/226.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/227.java b/Java/Easy/227.java new file mode 100644 index 00000000..982768c6 --- /dev/null +++ b/Java/Easy/227.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = null; + System.out.println(x); + } +} diff --git a/Java/Easy/228.java b/Java/Easy/228.java new file mode 100644 index 00000000..5e688afa --- /dev/null +++ b/Java/Easy/228.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = "Hello World"; + System.out.println(message.charAt(11)); + } +} diff --git a/Java/Easy/229.java b/Java/Easy/229.java new file mode 100644 index 00000000..dc039dae --- /dev/null +++ b/Java/Easy/229.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + arr.length(); + } +} diff --git a/Java/Easy/230.java b/Java/Easy/230.java new file mode 100644 index 00000000..bc2af979 --- /dev/null +++ b/Java/Easy/230.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List fruits = new ArrayList<>(); + fruits.add("Apple"); + fruits(0) = "Banana"; + } +} diff --git a/Java/Easy/231.java b/Java/Easy/231.java new file mode 100644 index 00000000..cf4f0e4a --- /dev/null +++ b/Java/Easy/231.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + text.replace('a', "b"); + System.out.println(text); + } +} diff --git a/Java/Easy/232.java b/Java/Easy/232.java new file mode 100644 index 00000000..d32c00d9 --- /dev/null +++ b/Java/Easy/232.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double value = Math.sqrt(25); + int result = value; + System.out.println(result); + } +} diff --git a/Java/Easy/233.java b/Java/Easy/233.java new file mode 100644 index 00000000..24859931 --- /dev/null +++ b/Java/Easy/233.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + int result = a + b; + System.out.println(result); + } +} diff --git a/Java/Easy/234.java b/Java/Easy/234.java new file mode 100644 index 00000000..9faa7094 --- /dev/null +++ b/Java/Easy/234.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + System.out.println(s.charAt(4)); + } +} diff --git a/Java/Easy/235.java b/Java/Easy/235.java new file mode 100644 index 00000000..bf8de9e2 --- /dev/null +++ b/Java/Easy/235.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x ? "Yes" : "No"); + } +} diff --git a/Java/Easy/236.java b/Java/Easy/236.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/236.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/237.java b/Java/Easy/237.java new file mode 100644 index 00000000..3f154c9c --- /dev/null +++ b/Java/Easy/237.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double result = Math.pow(5); + System.out.println(result); + } +} diff --git a/Java/Easy/238.java b/Java/Easy/238.java new file mode 100644 index 00000000..34efc881 --- /dev/null +++ b/Java/Easy/238.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String str = null; + if (str.equals("Hello")) { + System.out.println("Hello"); + } + } +} diff --git a/Java/Easy/239.java b/Java/Easy/239.java new file mode 100644 index 00000000..80527d07 --- /dev/null +++ b/Java/Easy/239.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 10; + System.out.println(a instanceof Integer); + } +} diff --git a/Java/Easy/240.java b/Java/Easy/240.java new file mode 100644 index 00000000..87da08b4 --- /dev/null +++ b/Java/Easy/240.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double num = 5 / 2; + System.out.println(num); + } +} diff --git a/Java/Easy/241.java b/Java/Easy/241.java new file mode 100644 index 00000000..d2cc5a18 --- /dev/null +++ b/Java/Easy/241.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"A", "B", "C"}; + arr[3] = "D"; + } +} diff --git a/Java/Easy/242.java b/Java/Easy/242.java new file mode 100644 index 00000000..9237bea8 --- /dev/null +++ b/Java/Easy/242.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]{1, 2, 3}; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/243.java b/Java/Easy/243.java new file mode 100644 index 00000000..bd60bdb0 --- /dev/null +++ b/Java/Easy/243.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = "Hello, World!"; + System.out.println(message.substring(1, 20)); + } +} diff --git a/Java/Easy/244.java b/Java/Easy/244.java new file mode 100644 index 00000000..f85cd68d --- /dev/null +++ b/Java/Easy/244.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.abs(); + System.out.println(x); + } +} diff --git a/Java/Easy/245.java b/Java/Easy/245.java new file mode 100644 index 00000000..b2a35c78 --- /dev/null +++ b/Java/Easy/245.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "Hello"; + System.out.println(text.subString(1, 4)); + } +} diff --git a/Java/Easy/246.java b/Java/Easy/246.java new file mode 100644 index 00000000..4a50e924 --- /dev/null +++ b/Java/Easy/246.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String message = "Hello"; + message.replace('e', "a"); + System.out.println(message); + } +} diff --git a/Java/Easy/247.java b/Java/Easy/247.java new file mode 100644 index 00000000..0a30e02f --- /dev/null +++ b/Java/Easy/247.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String str = null; + if (str.equals("Hello")) { + System.out.println("Text is Hello"); + } + } +} diff --git a/Java/Easy/248.java b/Java/Easy/248.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/248.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/249.java b/Java/Easy/249.java new file mode 100644 index 00000000..b943c481 --- /dev/null +++ b/Java/Easy/249.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5; + System.out.println(x ? "Positive" : "Negative"); + } +} diff --git a/Java/Easy/250.java b/Java/Easy/250.java new file mode 100644 index 00000000..6a44cb03 --- /dev/null +++ b/Java/Easy/250.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char c = "A"; + System.out.println(c); + } +} diff --git a/Java/Easy/91.java b/Java/Easy/91.java new file mode 100644 index 00000000..9237bea8 --- /dev/null +++ b/Java/Easy/91.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]{1, 2, 3}; + System.out.println(arr[0]); + } +} From ec78fa253c5f18cc2aa4eb6490df229de1b89f73 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:57:42 +0530 Subject: [PATCH 24/62] easy java uploaded --- Java/Easy/1.java | 6 ++++++ Java/Easy/10.java | 7 +++++++ Java/Easy/11.java | 6 ++++++ Java/Easy/12.java | 6 ++++++ Java/Easy/13.java | 7 +++++++ Java/Easy/14.java | 6 ++++++ Java/Easy/15.java | 6 ++++++ Java/Easy/16.java | 8 ++++++++ Java/Easy/17.java | 6 ++++++ Java/Easy/18.java | 8 ++++++++ Java/Easy/19.java | 7 +++++++ Java/Easy/2.java | 6 ++++++ Java/Easy/20.java | 6 ++++++ Java/Easy/21.java | 7 +++++++ Java/Easy/22.java | 6 ++++++ Java/Easy/23.java | 6 ++++++ Java/Easy/24.java | 7 +++++++ Java/Easy/25.java | 7 +++++++ Java/Easy/26.java | 6 ++++++ Java/Easy/27.java | 8 ++++++++ Java/Easy/28.java | 7 +++++++ Java/Easy/29.java | 7 +++++++ Java/Easy/3.java | 6 ++++++ Java/Easy/30.java | 6 ++++++ Java/Easy/31.java | 6 ++++++ Java/Easy/32.java | 7 +++++++ Java/Easy/33.java | 6 ++++++ Java/Easy/34.java | 6 ++++++ Java/Easy/35.java | 6 ++++++ Java/Easy/36.java | 6 ++++++ Java/Easy/37.java | 7 +++++++ Java/Easy/38.java | 6 ++++++ Java/Easy/39.java | 6 ++++++ Java/Easy/4.java | 7 +++++++ Java/Easy/40.java | 6 ++++++ Java/Easy/41.java | 7 +++++++ Java/Easy/42.java | 5 +++++ Java/Easy/43.java | 6 ++++++ Java/Easy/44.java | 7 +++++++ Java/Easy/45.java | 6 ++++++ Java/Easy/46.java | 6 ++++++ Java/Easy/47.java | 7 +++++++ Java/Easy/48.java | 6 ++++++ Java/Easy/49.java | 7 +++++++ Java/Easy/5.java | 6 ++++++ Java/Easy/50.java | 6 ++++++ Java/Easy/51.java | 8 ++++++++ Java/Easy/52.java | 6 ++++++ Java/Easy/53.java | 6 ++++++ Java/Easy/54.java | 7 +++++++ Java/Easy/55.java | 6 ++++++ Java/Easy/56.java | 7 +++++++ Java/Easy/57.java | 6 ++++++ Java/Easy/58.java | 7 +++++++ Java/Easy/59.java | 6 ++++++ Java/Easy/6.java | 6 ++++++ Java/Easy/60.java | 7 +++++++ Java/Easy/61.java | 8 ++++++++ Java/Easy/62.java | 9 +++++++++ Java/Easy/63.java | 11 +++++++++++ Java/Easy/64.java | 6 ++++++ Java/Easy/65.java | 8 ++++++++ Java/Easy/66.java | 7 +++++++ Java/Easy/67.java | 6 ++++++ Java/Easy/68.java | 6 ++++++ Java/Easy/69.java | 6 ++++++ Java/Easy/7.java | 6 ++++++ Java/Easy/70.java | 7 +++++++ Java/Easy/71.java | 6 ++++++ Java/Easy/72.java | 8 ++++++++ Java/Easy/73.java | 8 ++++++++ Java/Easy/74.java | 7 +++++++ Java/Easy/75.java | 8 ++++++++ Java/Easy/76.java | 6 ++++++ Java/Easy/77.java | 6 ++++++ Java/Easy/78.java | 7 +++++++ Java/Easy/79.java | 6 ++++++ Java/Easy/8.java | 7 +++++++ Java/Easy/80.java | 7 +++++++ Java/Easy/81.java | 7 +++++++ Java/Easy/82.java | 7 +++++++ Java/Easy/83.java | 7 +++++++ Java/Easy/84.java | 9 +++++++++ Java/Easy/85.java | 6 ++++++ Java/Easy/86.java | 8 ++++++++ Java/Easy/87.java | 6 ++++++ Java/Easy/88.java | 5 +++++ Java/Easy/89.java | 6 ++++++ Java/Easy/9.java | 7 +++++++ Java/Easy/90.java | 6 ++++++ 90 files changed, 598 insertions(+) create mode 100644 Java/Easy/1.java create mode 100644 Java/Easy/10.java create mode 100644 Java/Easy/11.java create mode 100644 Java/Easy/12.java create mode 100644 Java/Easy/13.java create mode 100644 Java/Easy/14.java create mode 100644 Java/Easy/15.java create mode 100644 Java/Easy/16.java create mode 100644 Java/Easy/17.java create mode 100644 Java/Easy/18.java create mode 100644 Java/Easy/19.java create mode 100644 Java/Easy/2.java create mode 100644 Java/Easy/20.java create mode 100644 Java/Easy/21.java create mode 100644 Java/Easy/22.java create mode 100644 Java/Easy/23.java create mode 100644 Java/Easy/24.java create mode 100644 Java/Easy/25.java create mode 100644 Java/Easy/26.java create mode 100644 Java/Easy/27.java create mode 100644 Java/Easy/28.java create mode 100644 Java/Easy/29.java create mode 100644 Java/Easy/3.java create mode 100644 Java/Easy/30.java create mode 100644 Java/Easy/31.java create mode 100644 Java/Easy/32.java create mode 100644 Java/Easy/33.java create mode 100644 Java/Easy/34.java create mode 100644 Java/Easy/35.java create mode 100644 Java/Easy/36.java create mode 100644 Java/Easy/37.java create mode 100644 Java/Easy/38.java create mode 100644 Java/Easy/39.java create mode 100644 Java/Easy/4.java create mode 100644 Java/Easy/40.java create mode 100644 Java/Easy/41.java create mode 100644 Java/Easy/42.java create mode 100644 Java/Easy/43.java create mode 100644 Java/Easy/44.java create mode 100644 Java/Easy/45.java create mode 100644 Java/Easy/46.java create mode 100644 Java/Easy/47.java create mode 100644 Java/Easy/48.java create mode 100644 Java/Easy/49.java create mode 100644 Java/Easy/5.java create mode 100644 Java/Easy/50.java create mode 100644 Java/Easy/51.java create mode 100644 Java/Easy/52.java create mode 100644 Java/Easy/53.java create mode 100644 Java/Easy/54.java create mode 100644 Java/Easy/55.java create mode 100644 Java/Easy/56.java create mode 100644 Java/Easy/57.java create mode 100644 Java/Easy/58.java create mode 100644 Java/Easy/59.java create mode 100644 Java/Easy/6.java create mode 100644 Java/Easy/60.java create mode 100644 Java/Easy/61.java create mode 100644 Java/Easy/62.java create mode 100644 Java/Easy/63.java create mode 100644 Java/Easy/64.java create mode 100644 Java/Easy/65.java create mode 100644 Java/Easy/66.java create mode 100644 Java/Easy/67.java create mode 100644 Java/Easy/68.java create mode 100644 Java/Easy/69.java create mode 100644 Java/Easy/7.java create mode 100644 Java/Easy/70.java create mode 100644 Java/Easy/71.java create mode 100644 Java/Easy/72.java create mode 100644 Java/Easy/73.java create mode 100644 Java/Easy/74.java create mode 100644 Java/Easy/75.java create mode 100644 Java/Easy/76.java create mode 100644 Java/Easy/77.java create mode 100644 Java/Easy/78.java create mode 100644 Java/Easy/79.java create mode 100644 Java/Easy/8.java create mode 100644 Java/Easy/80.java create mode 100644 Java/Easy/81.java create mode 100644 Java/Easy/82.java create mode 100644 Java/Easy/83.java create mode 100644 Java/Easy/84.java create mode 100644 Java/Easy/85.java create mode 100644 Java/Easy/86.java create mode 100644 Java/Easy/87.java create mode 100644 Java/Easy/88.java create mode 100644 Java/Easy/89.java create mode 100644 Java/Easy/9.java create mode 100644 Java/Easy/90.java diff --git a/Java/Easy/1.java b/Java/Easy/1.java new file mode 100644 index 00000000..34eaf973 --- /dev/null +++ b/Java/Easy/1.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5 + System.out.println(x); + } +} diff --git a/Java/Easy/10.java b/Java/Easy/10.java new file mode 100644 index 00000000..c8196709 --- /dev/null +++ b/Java/Easy/10.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "John"; + char letter = name.charAt(5); + System.out.println(letter); + } +} diff --git a/Java/Easy/11.java b/Java/Easy/11.java new file mode 100644 index 00000000..d96b2487 --- /dev/null +++ b/Java/Easy/11.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean isValid = True; + System.out.println(isValid); + } +} diff --git a/Java/Easy/12.java b/Java/Easy/12.java new file mode 100644 index 00000000..41eeac6a --- /dev/null +++ b/Java/Easy/12.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int number = "50"; + System.out.println(number); + } +} diff --git a/Java/Easy/13.java b/Java/Easy/13.java new file mode 100644 index 00000000..a8af40fa --- /dev/null +++ b/Java/Easy/13.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + System.out.println(a.equals(b)); + } +} diff --git a/Java/Easy/14.java b/Java/Easy/14.java new file mode 100644 index 00000000..ce681444 --- /dev/null +++ b/Java/Easy/14.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char ch = 'abc'; + System.out.println(ch); + } +} diff --git a/Java/Easy/15.java b/Java/Easy/15.java new file mode 100644 index 00000000..b52bd268 --- /dev/null +++ b/Java/Easy/15.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean isValid = 0; + System.out.println(isValid); + } +} diff --git a/Java/Easy/16.java b/Java/Easy/16.java new file mode 100644 index 00000000..9eb00157 --- /dev/null +++ b/Java/Easy/16.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = 10; + System.out.println(a > b ? "Greater" : "Smaller"); + else System.out.println("Equal"); + } +} diff --git a/Java/Easy/17.java b/Java/Easy/17.java new file mode 100644 index 00000000..b1f4b533 --- /dev/null +++ b/Java/Easy/17.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int value = null; + System.out.println(value); + } +} diff --git a/Java/Easy/18.java b/Java/Easy/18.java new file mode 100644 index 00000000..6086a9e1 --- /dev/null +++ b/Java/Easy/18.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + Integer x = 1000; + if (x == 1000) { + System.out.println("Equal"); + } + } +} diff --git a/Java/Easy/19.java b/Java/Easy/19.java new file mode 100644 index 00000000..f67a3ee8 --- /dev/null +++ b/Java/Easy/19.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr.add(10); + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/2.java b/Java/Easy/2.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/2.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/20.java b/Java/Easy/20.java new file mode 100644 index 00000000..5ec7f159 --- /dev/null +++ b/Java/Easy/20.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[-10]; + System.out.println(numbers.length); + } +} diff --git a/Java/Easy/21.java b/Java/Easy/21.java new file mode 100644 index 00000000..d008d0db --- /dev/null +++ b/Java/Easy/21.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 10, i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/22.java b/Java/Easy/22.java new file mode 100644 index 00000000..938c9b8f --- /dev/null +++ b/Java/Easy/22.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr.size()); + } +} diff --git a/Java/Easy/23.java b/Java/Easy/23.java new file mode 100644 index 00000000..9ac8a60b --- /dev/null +++ b/Java/Easy/23.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = "10"; + System.out.println(a); + } +} diff --git a/Java/Easy/24.java b/Java/Easy/24.java new file mode 100644 index 00000000..13bc35b2 --- /dev/null +++ b/Java/Easy/24.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] nums = new int[5]; + nums.add(10); + System.out.println(nums[0]); + } +} diff --git a/Java/Easy/25.java b/Java/Easy/25.java new file mode 100644 index 00000000..94ae4a30 --- /dev/null +++ b/Java/Easy/25.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "John"; + name.toUpperCase; + System.out.println(name); + } +} diff --git a/Java/Easy/26.java b/Java/Easy/26.java new file mode 100644 index 00000000..c185927a --- /dev/null +++ b/Java/Easy/26.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x.toString()); + } +} diff --git a/Java/Easy/27.java b/Java/Easy/27.java new file mode 100644 index 00000000..994e88f0 --- /dev/null +++ b/Java/Easy/27.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[5]; + for (int i = 0; i <= 5; i++) { + numbers[i] = i; + } + } +} diff --git a/Java/Easy/28.java b/Java/Easy/28.java new file mode 100644 index 00000000..a7fdb458 --- /dev/null +++ b/Java/Easy/28.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr[0] = "100"; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/29.java b/Java/Easy/29.java new file mode 100644 index 00000000..50955080 --- /dev/null +++ b/Java/Easy/29.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = "5"; + System.out.println(a + b); + } +} diff --git a/Java/Easy/3.java b/Java/Easy/3.java new file mode 100644 index 00000000..01b3cc04 --- /dev/null +++ b/Java/Easy/3.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name; + System.out.println(name); + } +} diff --git a/Java/Easy/30.java b/Java/Easy/30.java new file mode 100644 index 00000000..3b3c4f3a --- /dev/null +++ b/Java/Easy/30.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.sqrt(-1); + System.out.println(x); + } +} diff --git a/Java/Easy/31.java b/Java/Easy/31.java new file mode 100644 index 00000000..8859aebd --- /dev/null +++ b/Java/Easy/31.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a++ * ++a); + } +} diff --git a/Java/Easy/32.java b/Java/Easy/32.java new file mode 100644 index 00000000..57018eff --- /dev/null +++ b/Java/Easy/32.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + Integer b = null; + System.out.println(a + b); + } +} diff --git a/Java/Easy/33.java b/Java/Easy/33.java new file mode 100644 index 00000000..f00a56ef --- /dev/null +++ b/Java/Easy/33.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + System.out.println(s.reverse()); + } +} diff --git a/Java/Easy/34.java b/Java/Easy/34.java new file mode 100644 index 00000000..89fb0590 --- /dev/null +++ b/Java/Easy/34.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int num = 5; + num.equals(5); + } +} diff --git a/Java/Easy/35.java b/Java/Easy/35.java new file mode 100644 index 00000000..0fcb2232 --- /dev/null +++ b/Java/Easy/35.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = null; + System.out.println(name.length()); + } +} diff --git a/Java/Easy/36.java b/Java/Easy/36.java new file mode 100644 index 00000000..f9a30f16 --- /dev/null +++ b/Java/Easy/36.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + System.out.println(arr.toString()); + } +} diff --git a/Java/Easy/37.java b/Java/Easy/37.java new file mode 100644 index 00000000..12801dd7 --- /dev/null +++ b/Java/Easy/37.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + a++; + System.out.println(++a++); + } +} diff --git a/Java/Easy/38.java b/Java/Easy/38.java new file mode 100644 index 00000000..a74c0f08 --- /dev/null +++ b/Java/Easy/38.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr(0)); + } +} diff --git a/Java/Easy/39.java b/Java/Easy/39.java new file mode 100644 index 00000000..f66a8dbb --- /dev/null +++ b/Java/Easy/39.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.pow(2, 3); + System.out.println(x); + } +} diff --git a/Java/Easy/4.java b/Java/Easy/4.java new file mode 100644 index 00000000..a7fcce57 --- /dev/null +++ b/Java/Easy/4.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List names = new ArrayList<>(); + names.add("Alice"); + System.out.println(names[0]); + } +} diff --git a/Java/Easy/40.java b/Java/Easy/40.java new file mode 100644 index 00000000..c767dccc --- /dev/null +++ b/Java/Easy/40.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = "100"; + System.out.println(x); + } +} diff --git a/Java/Easy/41.java b/Java/Easy/41.java new file mode 100644 index 00000000..9908cfc4 --- /dev/null +++ b/Java/Easy/41.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("apple"); + System.out.println(list[0]); + } +} diff --git a/Java/Easy/42.java b/Java/Easy/42.java new file mode 100644 index 00000000..248a6787 --- /dev/null +++ b/Java/Easy/42.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(Math.pow(2)); + } +} diff --git a/Java/Easy/43.java b/Java/Easy/43.java new file mode 100644 index 00000000..b156edd8 --- /dev/null +++ b/Java/Easy/43.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + System.out.println(s.length(5)); + } +} diff --git a/Java/Easy/44.java b/Java/Easy/44.java new file mode 100644 index 00000000..e5aedcf1 --- /dev/null +++ b/Java/Easy/44.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List items = new ArrayList<>(); + items.add("Item1"); + System.out.println(items(0)); + } +} diff --git a/Java/Easy/45.java b/Java/Easy/45.java new file mode 100644 index 00000000..df46fd4d --- /dev/null +++ b/Java/Easy/45.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5.0 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/46.java b/Java/Easy/46.java new file mode 100644 index 00000000..8194d516 --- /dev/null +++ b/Java/Easy/46.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean isTrue = True; + System.out.println(isTrue); + } +} diff --git a/Java/Easy/47.java b/Java/Easy/47.java new file mode 100644 index 00000000..d7ab069c --- /dev/null +++ b/Java/Easy/47.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int result = Math.pow(a); + System.out.println(result); + } +} diff --git a/Java/Easy/48.java b/Java/Easy/48.java new file mode 100644 index 00000000..80ca4739 --- /dev/null +++ b/Java/Easy/48.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/49.java b/Java/Easy/49.java new file mode 100644 index 00000000..624b5bed --- /dev/null +++ b/Java/Easy/49.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + numbers.add(10); + System.out.println(numbers.get(0)); + } +} diff --git a/Java/Easy/5.java b/Java/Easy/5.java new file mode 100644 index 00000000..2670118f --- /dev/null +++ b/Java/Easy/5.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + System.out.println(arr); + } +} diff --git a/Java/Easy/50.java b/Java/Easy/50.java new file mode 100644 index 00000000..d94fb137 --- /dev/null +++ b/Java/Easy/50.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = "Java"; + System.out.println(name.indexOf(2)); + } +} diff --git a/Java/Easy/51.java b/Java/Easy/51.java new file mode 100644 index 00000000..6c1438c8 --- /dev/null +++ b/Java/Easy/51.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int number = 5; + if (number = 5) { + System.out.println("Number is 5"); + } + } +} diff --git a/Java/Easy/52.java b/Java/Easy/52.java new file mode 100644 index 00000000..bcbe4aa5 --- /dev/null +++ b/Java/Easy/52.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 10; + String s = 'Hello'; + } +} diff --git a/Java/Easy/53.java b/Java/Easy/53.java new file mode 100644 index 00000000..df06d34c --- /dev/null +++ b/Java/Easy/53.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr[5] = 10; + } +} diff --git a/Java/Easy/54.java b/Java/Easy/54.java new file mode 100644 index 00000000..b1de45bf --- /dev/null +++ b/Java/Easy/54.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 10 i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/55.java b/Java/Easy/55.java new file mode 100644 index 00000000..54cf07ae --- /dev/null +++ b/Java/Easy/55.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String greeting = Hello; + System.out.println(greeting); + } +} diff --git a/Java/Easy/56.java b/Java/Easy/56.java new file mode 100644 index 00000000..027e0290 --- /dev/null +++ b/Java/Easy/56.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 1; + double y = x / 0; + System.out.println(y); + } +} diff --git a/Java/Easy/57.java b/Java/Easy/57.java new file mode 100644 index 00000000..54cf07ae --- /dev/null +++ b/Java/Easy/57.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String greeting = Hello; + System.out.println(greeting); + } +} diff --git a/Java/Easy/58.java b/Java/Easy/58.java new file mode 100644 index 00000000..65381694 --- /dev/null +++ b/Java/Easy/58.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String message = "Hello, World!"; + char c = message.charAt(20); + System.out.println(c); + } +} diff --git a/Java/Easy/59.java b/Java/Easy/59.java new file mode 100644 index 00000000..af05903b --- /dev/null +++ b/Java/Easy/59.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] fruits = {"Apple", "Banana", "Mango"}; + System.out.println(fruits[-1]); + } +} diff --git a/Java/Easy/6.java b/Java/Easy/6.java new file mode 100644 index 00000000..5d22ef9e --- /dev/null +++ b/Java/Easy/6.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "abc"; + System.out.println(s.charAt(5)); + } +} diff --git a/Java/Easy/60.java b/Java/Easy/60.java new file mode 100644 index 00000000..a91aad94 --- /dev/null +++ b/Java/Easy/60.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10, b = 0; + int result = a / b; + System.out.println(result); + } +} diff --git a/Java/Easy/61.java b/Java/Easy/61.java new file mode 100644 index 00000000..6f9c6d49 --- /dev/null +++ b/Java/Easy/61.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i : arr) { + arr[i] = i * 2; + } + } +} diff --git a/Java/Easy/62.java b/Java/Easy/62.java new file mode 100644 index 00000000..d06be962 --- /dev/null +++ b/Java/Easy/62.java @@ -0,0 +1,9 @@ +class Main { + public static void main(String[] args) { + int x = 10; + while x > 0 { + System.out.println(x); + x--; + } + } +} diff --git a/Java/Easy/63.java b/Java/Easy/63.java new file mode 100644 index 00000000..6636055b --- /dev/null +++ b/Java/Easy/63.java @@ -0,0 +1,11 @@ +class Main { + public static void main(String[] args) { + int x = 5; + switch (x) { + case 5: + System.out.println("Five"); + default: + System.out.println("Default case"); + } + } +} diff --git a/Java/Easy/64.java b/Java/Easy/64.java new file mode 100644 index 00000000..76bf5189 --- /dev/null +++ b/Java/Easy/64.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[10]; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/65.java b/Java/Easy/65.java new file mode 100644 index 00000000..edfc1ba1 --- /dev/null +++ b/Java/Easy/65.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + double pi = 3.14159; + double radius = 5.0; + double area = Math.pi * radius * radius; + System.out.println(area); + } +} diff --git a/Java/Easy/66.java b/Java/Easy/66.java new file mode 100644 index 00000000..77f4fd8c --- /dev/null +++ b/Java/Easy/66.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = '10'; + System.out.println(a + b); + } +} diff --git a/Java/Easy/67.java b/Java/Easy/67.java new file mode 100644 index 00000000..c3409845 --- /dev/null +++ b/Java/Easy/67.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String str = null; + System.out.println(str.length()); + } +} diff --git a/Java/Easy/68.java b/Java/Easy/68.java new file mode 100644 index 00000000..003c7c4d --- /dev/null +++ b/Java/Easy/68.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char ch = "A"; + System.out.println(ch); + } +} diff --git a/Java/Easy/69.java b/Java/Easy/69.java new file mode 100644 index 00000000..f51f5106 --- /dev/null +++ b/Java/Easy/69.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x.equals(10)); + } +} diff --git a/Java/Easy/7.java b/Java/Easy/7.java new file mode 100644 index 00000000..3d113ded --- /dev/null +++ b/Java/Easy/7.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] nums = new int[-5]; + System.out.println(nums.length); + } +} diff --git a/Java/Easy/70.java b/Java/Easy/70.java new file mode 100644 index 00000000..97285f8b --- /dev/null +++ b/Java/Easy/70.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + s.toUppercase(); + System.out.println(s); + } +} diff --git a/Java/Easy/71.java b/Java/Easy/71.java new file mode 100644 index 00000000..cded88fb --- /dev/null +++ b/Java/Easy/71.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int result = 5 + ; + System.out.println(result); + } +} diff --git a/Java/Easy/72.java b/Java/Easy/72.java new file mode 100644 index 00000000..20e27221 --- /dev/null +++ b/Java/Easy/72.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String[] names = {"John", "Doe"}; + for (int i = 0; i < names.size(); i++) { + System.out.println(names[i]); + } + } +} diff --git a/Java/Easy/73.java b/Java/Easy/73.java new file mode 100644 index 00000000..a7f0fd5b --- /dev/null +++ b/Java/Easy/73.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int x = 5; + double y = 0.0; + double result = x % y; + System.out.println(result); + } +} diff --git a/Java/Easy/74.java b/Java/Easy/74.java new file mode 100644 index 00000000..68bd526e --- /dev/null +++ b/Java/Easy/74.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 100; + byte b = a; + System.out.println(b); + } +} diff --git a/Java/Easy/75.java b/Java/Easy/75.java new file mode 100644 index 00000000..45f002ab --- /dev/null +++ b/Java/Easy/75.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + int c = b + a; + System.out.println(c); + } +} diff --git a/Java/Easy/76.java b/Java/Easy/76.java new file mode 100644 index 00000000..db30001f --- /dev/null +++ b/Java/Easy/76.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 10; i++); + System.out.println(i); + } +} diff --git a/Java/Easy/77.java b/Java/Easy/77.java new file mode 100644 index 00000000..3b3c4f3a --- /dev/null +++ b/Java/Easy/77.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.sqrt(-1); + System.out.println(x); + } +} diff --git a/Java/Easy/78.java b/Java/Easy/78.java new file mode 100644 index 00000000..2ae3169b --- /dev/null +++ b/Java/Easy/78.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + Object obj = "Hello"; + int num = (int) obj; + System.out.println(num); + } +} diff --git a/Java/Easy/79.java b/Java/Easy/79.java new file mode 100644 index 00000000..9ac8a60b --- /dev/null +++ b/Java/Easy/79.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = "10"; + System.out.println(a); + } +} diff --git a/Java/Easy/8.java b/Java/Easy/8.java new file mode 100644 index 00000000..ca8957da --- /dev/null +++ b/Java/Easy/8.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double result = Math.pow(a); + System.out.println(result); + } +} diff --git a/Java/Easy/80.java b/Java/Easy/80.java new file mode 100644 index 00000000..4f4502f6 --- /dev/null +++ b/Java/Easy/80.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + a++; + System.out.println(a++); + } +} diff --git a/Java/Easy/81.java b/Java/Easy/81.java new file mode 100644 index 00000000..e184b67c --- /dev/null +++ b/Java/Easy/81.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + s = null; + System.out.println(s.toUpperCase()); + } +} diff --git a/Java/Easy/82.java b/Java/Easy/82.java new file mode 100644 index 00000000..dc1ce17b --- /dev/null +++ b/Java/Easy/82.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String s = Integer.parseInt(a); + System.out.println(s); + } +} diff --git a/Java/Easy/83.java b/Java/Easy/83.java new file mode 100644 index 00000000..cbc6b127 --- /dev/null +++ b/Java/Easy/83.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + s.replace('a', "o"); + System.out.println(s); + } +} diff --git a/Java/Easy/84.java b/Java/Easy/84.java new file mode 100644 index 00000000..dde403c5 --- /dev/null +++ b/Java/Easy/84.java @@ -0,0 +1,9 @@ +class Main { + public static void main(String[] args) { + int a = 0; + while (a = 10) { + System.out.println(a); + a++; + } + } +} diff --git a/Java/Easy/85.java b/Java/Easy/85.java new file mode 100644 index 00000000..a50d7082 --- /dev/null +++ b/Java/Easy/85.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] fruits = new String[]{"Apple", "Orange", "Banana"}; + System.out.println(fruits(0)); + } +} diff --git a/Java/Easy/86.java b/Java/Easy/86.java new file mode 100644 index 00000000..d28f68dd --- /dev/null +++ b/Java/Easy/86.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 1; + do { + System.out.println(a); + } while a < 10; + } +} diff --git a/Java/Easy/87.java b/Java/Easy/87.java new file mode 100644 index 00000000..16b612d2 --- /dev/null +++ b/Java/Easy/87.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = 'Hello World'; + System.out.println(message); + } +} diff --git a/Java/Easy/88.java b/Java/Easy/88.java new file mode 100644 index 00000000..fbdaea07 --- /dev/null +++ b/Java/Easy/88.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println("Sum of 5 and 10 is: " + 5 + 10); + } +} diff --git a/Java/Easy/89.java b/Java/Easy/89.java new file mode 100644 index 00000000..e6d97677 --- /dev/null +++ b/Java/Easy/89.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] nums = {1, 2, 3}; + System.out.println(nums[-1]); + } +} diff --git a/Java/Easy/9.java b/Java/Easy/9.java new file mode 100644 index 00000000..adf3afbf --- /dev/null +++ b/Java/Easy/9.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[3]; + numbers[0] = 5; + numbers[3] = 10; + } +} diff --git a/Java/Easy/90.java b/Java/Easy/90.java new file mode 100644 index 00000000..6bd6f77f --- /dev/null +++ b/Java/Easy/90.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr.length()); + } +} From 7c9e4ae1d363b70243eff107b9d512206a184e70 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:59:45 +0530 Subject: [PATCH 25/62] java easy uploaded --- Java/Easy/100.java | 6 ++++++ Java/Easy/101.java | 6 ++++++ Java/Easy/102.java | 7 +++++++ Java/Easy/103.java | 7 +++++++ Java/Easy/104.java | 6 ++++++ Java/Easy/105.java | 6 ++++++ Java/Easy/106.java | 6 ++++++ Java/Easy/107.java | 6 ++++++ Java/Easy/108.java | 5 +++++ Java/Easy/109.java | 8 ++++++++ Java/Easy/110.java | 6 ++++++ Java/Easy/111.java | 8 ++++++++ Java/Easy/112.java | 6 ++++++ Java/Easy/113.java | 7 +++++++ Java/Easy/114.java | 6 ++++++ Java/Easy/115.java | 6 ++++++ Java/Easy/116.java | 7 +++++++ Java/Easy/117.java | 6 ++++++ Java/Easy/118.java | 6 ++++++ Java/Easy/119.java | 7 +++++++ Java/Easy/120.java | 7 +++++++ Java/Easy/121.java | 7 +++++++ Java/Easy/122.java | 8 ++++++++ Java/Easy/123.java | 8 ++++++++ Java/Easy/124.java | 7 +++++++ Java/Easy/125.java | 7 +++++++ Java/Easy/126.java | 6 ++++++ Java/Easy/127.java | 6 ++++++ Java/Easy/128.java | 7 +++++++ Java/Easy/129.java | 8 ++++++++ Java/Easy/130.java | 7 +++++++ Java/Easy/131.java | 8 ++++++++ Java/Easy/132.java | 7 +++++++ Java/Easy/133.java | 6 ++++++ Java/Easy/134.java | 7 +++++++ Java/Easy/135.java | 6 ++++++ Java/Easy/136.java | 6 ++++++ Java/Easy/137.java | 7 +++++++ Java/Easy/138.java | 6 ++++++ Java/Easy/139.java | 6 ++++++ Java/Easy/140.java | 6 ++++++ Java/Easy/141.java | 7 +++++++ Java/Easy/142.java | 8 ++++++++ Java/Easy/143.java | 6 ++++++ Java/Easy/144.java | 7 +++++++ Java/Easy/145.java | 7 +++++++ Java/Easy/146.java | 8 ++++++++ Java/Easy/147.java | 6 ++++++ Java/Easy/148.java | 6 ++++++ Java/Easy/149.java | 7 +++++++ Java/Easy/150.java | 8 ++++++++ Java/Easy/151.java | 8 ++++++++ Java/Easy/152.java | 6 ++++++ Java/Easy/153.java | 6 ++++++ Java/Easy/154.java | 8 ++++++++ Java/Easy/155.java | 6 ++++++ Java/Easy/156.java | 6 ++++++ Java/Easy/157.java | 7 +++++++ Java/Easy/158.java | 6 ++++++ Java/Easy/159.java | 7 +++++++ Java/Easy/160.java | 6 ++++++ Java/Easy/161.java | 8 ++++++++ Java/Easy/162.java | 8 ++++++++ Java/Easy/163.java | 6 ++++++ Java/Easy/164.java | 6 ++++++ Java/Easy/165.java | 6 ++++++ Java/Easy/166.java | 7 +++++++ Java/Easy/92.java | 7 +++++++ Java/Easy/93.java | 8 ++++++++ Java/Easy/94.java | 6 ++++++ Java/Easy/95.java | 6 ++++++ Java/Easy/96.java | 6 ++++++ Java/Easy/97.java | 7 +++++++ Java/Easy/98.java | 7 +++++++ Java/Easy/99.java | 6 ++++++ 75 files changed, 501 insertions(+) create mode 100644 Java/Easy/100.java create mode 100644 Java/Easy/101.java create mode 100644 Java/Easy/102.java create mode 100644 Java/Easy/103.java create mode 100644 Java/Easy/104.java create mode 100644 Java/Easy/105.java create mode 100644 Java/Easy/106.java create mode 100644 Java/Easy/107.java create mode 100644 Java/Easy/108.java create mode 100644 Java/Easy/109.java create mode 100644 Java/Easy/110.java create mode 100644 Java/Easy/111.java create mode 100644 Java/Easy/112.java create mode 100644 Java/Easy/113.java create mode 100644 Java/Easy/114.java create mode 100644 Java/Easy/115.java create mode 100644 Java/Easy/116.java create mode 100644 Java/Easy/117.java create mode 100644 Java/Easy/118.java create mode 100644 Java/Easy/119.java create mode 100644 Java/Easy/120.java create mode 100644 Java/Easy/121.java create mode 100644 Java/Easy/122.java create mode 100644 Java/Easy/123.java create mode 100644 Java/Easy/124.java create mode 100644 Java/Easy/125.java create mode 100644 Java/Easy/126.java create mode 100644 Java/Easy/127.java create mode 100644 Java/Easy/128.java create mode 100644 Java/Easy/129.java create mode 100644 Java/Easy/130.java create mode 100644 Java/Easy/131.java create mode 100644 Java/Easy/132.java create mode 100644 Java/Easy/133.java create mode 100644 Java/Easy/134.java create mode 100644 Java/Easy/135.java create mode 100644 Java/Easy/136.java create mode 100644 Java/Easy/137.java create mode 100644 Java/Easy/138.java create mode 100644 Java/Easy/139.java create mode 100644 Java/Easy/140.java create mode 100644 Java/Easy/141.java create mode 100644 Java/Easy/142.java create mode 100644 Java/Easy/143.java create mode 100644 Java/Easy/144.java create mode 100644 Java/Easy/145.java create mode 100644 Java/Easy/146.java create mode 100644 Java/Easy/147.java create mode 100644 Java/Easy/148.java create mode 100644 Java/Easy/149.java create mode 100644 Java/Easy/150.java create mode 100644 Java/Easy/151.java create mode 100644 Java/Easy/152.java create mode 100644 Java/Easy/153.java create mode 100644 Java/Easy/154.java create mode 100644 Java/Easy/155.java create mode 100644 Java/Easy/156.java create mode 100644 Java/Easy/157.java create mode 100644 Java/Easy/158.java create mode 100644 Java/Easy/159.java create mode 100644 Java/Easy/160.java create mode 100644 Java/Easy/161.java create mode 100644 Java/Easy/162.java create mode 100644 Java/Easy/163.java create mode 100644 Java/Easy/164.java create mode 100644 Java/Easy/165.java create mode 100644 Java/Easy/166.java create mode 100644 Java/Easy/92.java create mode 100644 Java/Easy/93.java create mode 100644 Java/Easy/94.java create mode 100644 Java/Easy/95.java create mode 100644 Java/Easy/96.java create mode 100644 Java/Easy/97.java create mode 100644 Java/Easy/98.java create mode 100644 Java/Easy/99.java diff --git a/Java/Easy/100.java b/Java/Easy/100.java new file mode 100644 index 00000000..57792c6e --- /dev/null +++ b/Java/Easy/100.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] names = {"Alice", "Bob"}; + System.out.println(names.get(0)); + } +} diff --git a/Java/Easy/101.java b/Java/Easy/101.java new file mode 100644 index 00000000..f85cd68d --- /dev/null +++ b/Java/Easy/101.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.abs(); + System.out.println(x); + } +} diff --git a/Java/Easy/102.java b/Java/Easy/102.java new file mode 100644 index 00000000..cd7935f4 --- /dev/null +++ b/Java/Easy/102.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 5) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/103.java b/Java/Easy/103.java new file mode 100644 index 00000000..624b5bed --- /dev/null +++ b/Java/Easy/103.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + numbers.add(10); + System.out.println(numbers.get(0)); + } +} diff --git a/Java/Easy/104.java b/Java/Easy/104.java new file mode 100644 index 00000000..5118a1c6 --- /dev/null +++ b/Java/Easy/104.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] items = {"apple", "banana"}; + System.out.println(items[2]); + } +} diff --git a/Java/Easy/105.java b/Java/Easy/105.java new file mode 100644 index 00000000..8439b171 --- /dev/null +++ b/Java/Easy/105.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "java"; + System.out.println(text.ToUpperCase()); + } +} diff --git a/Java/Easy/106.java b/Java/Easy/106.java new file mode 100644 index 00000000..ac32ebe6 --- /dev/null +++ b/Java/Easy/106.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x; + System.out.println(x); + } +} diff --git a/Java/Easy/107.java b/Java/Easy/107.java new file mode 100644 index 00000000..26a1e0ff --- /dev/null +++ b/Java/Easy/107.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers.toString()); + } +} diff --git a/Java/Easy/108.java b/Java/Easy/108.java new file mode 100644 index 00000000..98fadf9d --- /dev/null +++ b/Java/Easy/108.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(5. / 0); + } +} diff --git a/Java/Easy/109.java b/Java/Easy/109.java new file mode 100644 index 00000000..6f9c6d49 --- /dev/null +++ b/Java/Easy/109.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i : arr) { + arr[i] = i * 2; + } + } +} diff --git a/Java/Easy/110.java b/Java/Easy/110.java new file mode 100644 index 00000000..427d2e9c --- /dev/null +++ b/Java/Easy/110.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.pow(2); + System.out.println(x); + } +} diff --git a/Java/Easy/111.java b/Java/Easy/111.java new file mode 100644 index 00000000..b7e3f6f3 --- /dev/null +++ b/Java/Easy/111.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i = 0; i <= arr.length; i++) { + arr[i] = i; + } + } +} diff --git a/Java/Easy/112.java b/Java/Easy/112.java new file mode 100644 index 00000000..8a9aca9b --- /dev/null +++ b/Java/Easy/112.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + arr.add(5); + } +} diff --git a/Java/Easy/113.java b/Java/Easy/113.java new file mode 100644 index 00000000..a85faf77 --- /dev/null +++ b/Java/Easy/113.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + s.toLowerCase; + System.out.println(s); + } +} diff --git a/Java/Easy/114.java b/Java/Easy/114.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/114.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/115.java b/Java/Easy/115.java new file mode 100644 index 00000000..6bd6f77f --- /dev/null +++ b/Java/Easy/115.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/116.java b/Java/Easy/116.java new file mode 100644 index 00000000..ea5fc120 --- /dev/null +++ b/Java/Easy/116.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "apple"; + s.charAt(5); + System.out.println(s); + } +} diff --git a/Java/Easy/117.java b/Java/Easy/117.java new file mode 100644 index 00000000..88c65db6 --- /dev/null +++ b/Java/Easy/117.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String str = 100; + System.out.println(str); + } +} diff --git a/Java/Easy/118.java b/Java/Easy/118.java new file mode 100644 index 00000000..5ec7f159 --- /dev/null +++ b/Java/Easy/118.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[-10]; + System.out.println(numbers.length); + } +} diff --git a/Java/Easy/119.java b/Java/Easy/119.java new file mode 100644 index 00000000..d6255ff3 --- /dev/null +++ b/Java/Easy/119.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Alice"); + System.out.println(list[0]); + } +} diff --git a/Java/Easy/120.java b/Java/Easy/120.java new file mode 100644 index 00000000..6be93752 --- /dev/null +++ b/Java/Easy/120.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List names = new ArrayList<>(); + names.add("John", "Doe"); + System.out.println(names); + } +} diff --git a/Java/Easy/121.java b/Java/Easy/121.java new file mode 100644 index 00000000..b3e8adc4 --- /dev/null +++ b/Java/Easy/121.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int result = Math.pow(a, 2); + System.out.println(result); + } +} diff --git a/Java/Easy/122.java b/Java/Easy/122.java new file mode 100644 index 00000000..b5f3eec0 --- /dev/null +++ b/Java/Easy/122.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int x = 5; + if (x > 10) + System.out.println("x is greater than 10"); + System.out.println("This will always print"); + } +} diff --git a/Java/Easy/123.java b/Java/Easy/123.java new file mode 100644 index 00000000..b7e88c68 --- /dev/null +++ b/Java/Easy/123.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int num = 0; + do { + System.out.println(num); + } while num < 5; + } +} diff --git a/Java/Easy/124.java b/Java/Easy/124.java new file mode 100644 index 00000000..9325aa76 --- /dev/null +++ b/Java/Easy/124.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String s = (String) a; + System.out.println(s); + } +} diff --git a/Java/Easy/125.java b/Java/Easy/125.java new file mode 100644 index 00000000..3126e17b --- /dev/null +++ b/Java/Easy/125.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String str = "hello"; + str.concat(" world"); + System.out.println(str); + } +} diff --git a/Java/Easy/126.java b/Java/Easy/126.java new file mode 100644 index 00000000..53e570bd --- /dev/null +++ b/Java/Easy/126.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5; + System.out.println("Square of x is: " + Math.square(x)); + } +} diff --git a/Java/Easy/127.java b/Java/Easy/127.java new file mode 100644 index 00000000..1423a152 --- /dev/null +++ b/Java/Easy/127.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] colors = {"red", "green", "blue"}; + System.out.println(colors[3]); + } +} diff --git a/Java/Easy/128.java b/Java/Easy/128.java new file mode 100644 index 00000000..14d772f9 --- /dev/null +++ b/Java/Easy/128.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "Alice"; + char letter = name[0]; + System.out.println(letter); + } +} diff --git a/Java/Easy/129.java b/Java/Easy/129.java new file mode 100644 index 00000000..6a63b740 --- /dev/null +++ b/Java/Easy/129.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int i = 0; + for (; i < 5) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/130.java b/Java/Easy/130.java new file mode 100644 index 00000000..cd88454b --- /dev/null +++ b/Java/Easy/130.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String b = (String) a; + System.out.println(b); + } +} diff --git a/Java/Easy/131.java b/Java/Easy/131.java new file mode 100644 index 00000000..002ae5fb --- /dev/null +++ b/Java/Easy/131.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 5) { + System.out.println(i); + } + System.out.println(i); + } +} diff --git a/Java/Easy/132.java b/Java/Easy/132.java new file mode 100644 index 00000000..6f13ecab --- /dev/null +++ b/Java/Easy/132.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "java"; + s.replace('a', "o"); + System.out.println(s); + } +} diff --git a/Java/Easy/133.java b/Java/Easy/133.java new file mode 100644 index 00000000..ce71a88a --- /dev/null +++ b/Java/Easy/133.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a++); + } +} diff --git a/Java/Easy/134.java b/Java/Easy/134.java new file mode 100644 index 00000000..dc95be15 --- /dev/null +++ b/Java/Easy/134.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + numbers.add(5); + System.out.println(numbers.get(0)); + } +} diff --git a/Java/Easy/135.java b/Java/Easy/135.java new file mode 100644 index 00000000..871c31d4 --- /dev/null +++ b/Java/Easy/135.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = null; + System.out.println(message.length()); + } +} diff --git a/Java/Easy/136.java b/Java/Easy/136.java new file mode 100644 index 00000000..619444e9 --- /dev/null +++ b/Java/Easy/136.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char c = 'Hello'; + System.out.println(c); + } +} diff --git a/Java/Easy/137.java b/Java/Easy/137.java new file mode 100644 index 00000000..cc9b92f1 --- /dev/null +++ b/Java/Easy/137.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String s = Integer.toString(a); + System.out.println(s * 2); + } +} diff --git a/Java/Easy/138.java b/Java/Easy/138.java new file mode 100644 index 00000000..5706478f --- /dev/null +++ b/Java/Easy/138.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.abs(); + System.out.println(x); + } +} diff --git a/Java/Easy/139.java b/Java/Easy/139.java new file mode 100644 index 00000000..8115aebb --- /dev/null +++ b/Java/Easy/139.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"apple", "banana", "orange"}; + System.out.println(arr.size()); + } +} diff --git a/Java/Easy/140.java b/Java/Easy/140.java new file mode 100644 index 00000000..80ca4739 --- /dev/null +++ b/Java/Easy/140.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/141.java b/Java/Easy/141.java new file mode 100644 index 00000000..95d1f92f --- /dev/null +++ b/Java/Easy/141.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + String s = (String) a; + System.out.println(s); + } +} diff --git a/Java/Easy/142.java b/Java/Easy/142.java new file mode 100644 index 00000000..24859931 --- /dev/null +++ b/Java/Easy/142.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + int result = a + b; + System.out.println(result); + } +} diff --git a/Java/Easy/143.java b/Java/Easy/143.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/143.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/144.java b/Java/Easy/144.java new file mode 100644 index 00000000..be674e14 --- /dev/null +++ b/Java/Easy/144.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + double result = a / 0; + System.out.println(result); + } +} diff --git a/Java/Easy/145.java b/Java/Easy/145.java new file mode 100644 index 00000000..05eeb233 --- /dev/null +++ b/Java/Easy/145.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + s.concat("world"); + System.out.println(s); + } +} diff --git a/Java/Easy/146.java b/Java/Easy/146.java new file mode 100644 index 00000000..09e5ded9 --- /dev/null +++ b/Java/Easy/146.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int x = 5; + if (x > 0) + System.out.println("Positive"); + System.out.println("Always printed"); + } +} diff --git a/Java/Easy/147.java b/Java/Easy/147.java new file mode 100644 index 00000000..9237bea8 --- /dev/null +++ b/Java/Easy/147.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]{1, 2, 3}; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/148.java b/Java/Easy/148.java new file mode 100644 index 00000000..01b3cc04 --- /dev/null +++ b/Java/Easy/148.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name; + System.out.println(name); + } +} diff --git a/Java/Easy/149.java b/Java/Easy/149.java new file mode 100644 index 00000000..093ac887 --- /dev/null +++ b/Java/Easy/149.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double x = 5.0; + int result = x; + System.out.println(result); + } +} diff --git a/Java/Easy/150.java b/Java/Easy/150.java new file mode 100644 index 00000000..f9054c84 --- /dev/null +++ b/Java/Easy/150.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int num = 10; + if (num = 10) { + System.out.println("Number is 10"); + } + } +} diff --git a/Java/Easy/151.java b/Java/Easy/151.java new file mode 100644 index 00000000..c7463fec --- /dev/null +++ b/Java/Easy/151.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + for (int i : arr) { + arr[i] = i * 2; + } + } +} diff --git a/Java/Easy/152.java b/Java/Easy/152.java new file mode 100644 index 00000000..b5b159a6 --- /dev/null +++ b/Java/Easy/152.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + arr[3] = 10; + } +} diff --git a/Java/Easy/153.java b/Java/Easy/153.java new file mode 100644 index 00000000..8b5c3d5f --- /dev/null +++ b/Java/Easy/153.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a = 10); + } +} diff --git a/Java/Easy/154.java b/Java/Easy/154.java new file mode 100644 index 00000000..ea004627 --- /dev/null +++ b/Java/Easy/154.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + int b = 0; + int result = a / b; + System.out.println(result); + } +} diff --git a/Java/Easy/155.java b/Java/Easy/155.java new file mode 100644 index 00000000..f51f5106 --- /dev/null +++ b/Java/Easy/155.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x.equals(10)); + } +} diff --git a/Java/Easy/156.java b/Java/Easy/156.java new file mode 100644 index 00000000..34ee1940 --- /dev/null +++ b/Java/Easy/156.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 10 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/157.java b/Java/Easy/157.java new file mode 100644 index 00000000..a9328518 --- /dev/null +++ b/Java/Easy/157.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + char firstChar = text[0]; + System.out.println(firstChar); + } +} diff --git a/Java/Easy/158.java b/Java/Easy/158.java new file mode 100644 index 00000000..b943c481 --- /dev/null +++ b/Java/Easy/158.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5; + System.out.println(x ? "Positive" : "Negative"); + } +} diff --git a/Java/Easy/159.java b/Java/Easy/159.java new file mode 100644 index 00000000..81668ff7 --- /dev/null +++ b/Java/Easy/159.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String str = "123"; + int number = Integer.toInt(str); + System.out.println(number); + } +} diff --git a/Java/Easy/160.java b/Java/Easy/160.java new file mode 100644 index 00000000..a5467a36 --- /dev/null +++ b/Java/Easy/160.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + System.out.println(arr(0)); + } +} diff --git a/Java/Easy/161.java b/Java/Easy/161.java new file mode 100644 index 00000000..80218687 --- /dev/null +++ b/Java/Easy/161.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + boolean isTrue = false; + if (isTrue = true) { + System.out.println("True"); + } + } +} diff --git a/Java/Easy/162.java b/Java/Easy/162.java new file mode 100644 index 00000000..15f54456 --- /dev/null +++ b/Java/Easy/162.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + float b = 10.5; + int c = a + b; + System.out.println(c); + } +} diff --git a/Java/Easy/163.java b/Java/Easy/163.java new file mode 100644 index 00000000..b2a35c78 --- /dev/null +++ b/Java/Easy/163.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "Hello"; + System.out.println(text.subString(1, 4)); + } +} diff --git a/Java/Easy/164.java b/Java/Easy/164.java new file mode 100644 index 00000000..dc039dae --- /dev/null +++ b/Java/Easy/164.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + arr.length(); + } +} diff --git a/Java/Easy/165.java b/Java/Easy/165.java new file mode 100644 index 00000000..e8a234b3 --- /dev/null +++ b/Java/Easy/165.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a++ + ++a); + } +} diff --git a/Java/Easy/166.java b/Java/Easy/166.java new file mode 100644 index 00000000..d6255ff3 --- /dev/null +++ b/Java/Easy/166.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Alice"); + System.out.println(list[0]); + } +} diff --git a/Java/Easy/92.java b/Java/Easy/92.java new file mode 100644 index 00000000..4dd45235 --- /dev/null +++ b/Java/Easy/92.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double value = 10.5; + int result = value + 5; + System.out.println(result); + } +} diff --git a/Java/Easy/93.java b/Java/Easy/93.java new file mode 100644 index 00000000..2de7cdc8 --- /dev/null +++ b/Java/Easy/93.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String text = null; + if (text.equals("Hello")) { + System.out.println("Text is Hello"); + } + } +} diff --git a/Java/Easy/94.java b/Java/Easy/94.java new file mode 100644 index 00000000..e10af0a1 --- /dev/null +++ b/Java/Easy/94.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String result = 5 + 10; + System.out.println(result); + } +} diff --git a/Java/Easy/95.java b/Java/Easy/95.java new file mode 100644 index 00000000..619444e9 --- /dev/null +++ b/Java/Easy/95.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char c = 'Hello'; + System.out.println(c); + } +} diff --git a/Java/Easy/96.java b/Java/Easy/96.java new file mode 100644 index 00000000..46e92b7e --- /dev/null +++ b/Java/Easy/96.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int i = 10; + System.out.println(++i++); + } +} diff --git a/Java/Easy/97.java b/Java/Easy/97.java new file mode 100644 index 00000000..ace382ee --- /dev/null +++ b/Java/Easy/97.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + final int a = 5; + a = 10; + System.out.println(a); + } +} diff --git a/Java/Easy/98.java b/Java/Easy/98.java new file mode 100644 index 00000000..f67a3ee8 --- /dev/null +++ b/Java/Easy/98.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr.add(10); + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/99.java b/Java/Easy/99.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/99.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} From 863df4c72fb10ec53a26b18ec61757f1bf7be8f1 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 18:01:10 +0530 Subject: [PATCH 26/62] java medium uploaded --- Java/Medium/1.java | 22 +++++++++++++++++ Java/Medium/10.java | 29 +++++++++++++++++++++++ Java/Medium/11.java | 22 +++++++++++++++++ Java/Medium/12.java | 13 +++++++++++ Java/Medium/13.java | 20 ++++++++++++++++ Java/Medium/14.java | 23 ++++++++++++++++++ Java/Medium/15.java | 23 ++++++++++++++++++ Java/Medium/16.java | 29 +++++++++++++++++++++++ Java/Medium/17.java | 23 ++++++++++++++++++ Java/Medium/18.java | 13 +++++++++++ Java/Medium/19.java | 13 +++++++++++ Java/Medium/2.java | 49 ++++++++++++++++++++++++++++++++++++++ Java/Medium/20.java | 17 ++++++++++++++ Java/Medium/21.java | 35 ++++++++++++++++++++++++++++ Java/Medium/22.java | 18 ++++++++++++++ Java/Medium/23.java | 27 +++++++++++++++++++++ Java/Medium/24.java | 17 ++++++++++++++ Java/Medium/25.java | 25 ++++++++++++++++++++ Java/Medium/26.java | 24 +++++++++++++++++++ Java/Medium/27.java | 24 +++++++++++++++++++ Java/Medium/28.java | 25 ++++++++++++++++++++ Java/Medium/29.java | 21 +++++++++++++++++ Java/Medium/3.java | 15 ++++++++++++ Java/Medium/30.java | 22 +++++++++++++++++ Java/Medium/31.java | 32 +++++++++++++++++++++++++ Java/Medium/32.java | 22 +++++++++++++++++ Java/Medium/33.java | 42 +++++++++++++++++++++++++++++++++ Java/Medium/34.java | 31 ++++++++++++++++++++++++ Java/Medium/35.java | 29 +++++++++++++++++++++++ Java/Medium/36.java | 32 +++++++++++++++++++++++++ Java/Medium/37.java | 40 +++++++++++++++++++++++++++++++ Java/Medium/38.java | 37 +++++++++++++++++++++++++++++ Java/Medium/39.java | 40 +++++++++++++++++++++++++++++++ Java/Medium/4.java | 17 ++++++++++++++ Java/Medium/40.java | 28 ++++++++++++++++++++++ Java/Medium/41.java | 29 +++++++++++++++++++++++ Java/Medium/42.java | 36 ++++++++++++++++++++++++++++ Java/Medium/43.java | 26 +++++++++++++++++++++ Java/Medium/44.java | 19 +++++++++++++++ Java/Medium/45.java | 34 +++++++++++++++++++++++++++ Java/Medium/46.java | 36 ++++++++++++++++++++++++++++ Java/Medium/47.java | 32 +++++++++++++++++++++++++ Java/Medium/48.java | 26 +++++++++++++++++++++ Java/Medium/49.java | 33 ++++++++++++++++++++++++++ Java/Medium/5.java | 28 ++++++++++++++++++++++ Java/Medium/50.java | 32 +++++++++++++++++++++++++ Java/Medium/6.java | 20 ++++++++++++++++ Java/Medium/7.java | 17 ++++++++++++++ Java/Medium/8.java | 36 ++++++++++++++++++++++++++++ Java/Medium/9.java | 57 +++++++++++++++++++++++++++++++++++++++++++++ 50 files changed, 1360 insertions(+) create mode 100644 Java/Medium/1.java create mode 100644 Java/Medium/10.java create mode 100644 Java/Medium/11.java create mode 100644 Java/Medium/12.java create mode 100644 Java/Medium/13.java create mode 100644 Java/Medium/14.java create mode 100644 Java/Medium/15.java create mode 100644 Java/Medium/16.java create mode 100644 Java/Medium/17.java create mode 100644 Java/Medium/18.java create mode 100644 Java/Medium/19.java create mode 100644 Java/Medium/2.java create mode 100644 Java/Medium/20.java create mode 100644 Java/Medium/21.java create mode 100644 Java/Medium/22.java create mode 100644 Java/Medium/23.java create mode 100644 Java/Medium/24.java create mode 100644 Java/Medium/25.java create mode 100644 Java/Medium/26.java create mode 100644 Java/Medium/27.java create mode 100644 Java/Medium/28.java create mode 100644 Java/Medium/29.java create mode 100644 Java/Medium/3.java create mode 100644 Java/Medium/30.java create mode 100644 Java/Medium/31.java create mode 100644 Java/Medium/32.java create mode 100644 Java/Medium/33.java create mode 100644 Java/Medium/34.java create mode 100644 Java/Medium/35.java create mode 100644 Java/Medium/36.java create mode 100644 Java/Medium/37.java create mode 100644 Java/Medium/38.java create mode 100644 Java/Medium/39.java create mode 100644 Java/Medium/4.java create mode 100644 Java/Medium/40.java create mode 100644 Java/Medium/41.java create mode 100644 Java/Medium/42.java create mode 100644 Java/Medium/43.java create mode 100644 Java/Medium/44.java create mode 100644 Java/Medium/45.java create mode 100644 Java/Medium/46.java create mode 100644 Java/Medium/47.java create mode 100644 Java/Medium/48.java create mode 100644 Java/Medium/49.java create mode 100644 Java/Medium/5.java create mode 100644 Java/Medium/50.java create mode 100644 Java/Medium/6.java create mode 100644 Java/Medium/7.java create mode 100644 Java/Medium/8.java create mode 100644 Java/Medium/9.java diff --git a/Java/Medium/1.java b/Java/Medium/1.java new file mode 100644 index 00000000..aafae381 --- /dev/null +++ b/Java/Medium/1.java @@ -0,0 +1,22 @@ +// Question: Complete the binary search algorithm by ensuring it handles edge cases like empty arrays and target values outside the array. + +class Main { + public static int binarySearch(int[] arr, int target) { + int left = 0, right = arr.length - 1; + while (left <= right) { + int mid = (left + right) / 2; + if (arr[mid] == target) { + return mid; + } else if (arr[mid] < target) { + left = mid + 1; + } else { + right = mid - 1; + } + } + return -1; + } + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5}; + System.out.println(binarySearch(arr, 3)); + } +} diff --git a/Java/Medium/10.java b/Java/Medium/10.java new file mode 100644 index 00000000..5357ecef --- /dev/null +++ b/Java/Medium/10.java @@ -0,0 +1,29 @@ +// Question: Complete the Bubble Sort algorithm by ensuring it handles edge cases and sorts the array in ascending order. + +class Main { + public static void bubbleSort(int[] arr) { + int n = arr.length; + boolean swapped; + for (int i = 0; i < n - 1; i++) { + swapped = false; + for (int j = 0; j < n - i - 1; j++) { + if (arr[j] > arr[j + 1]) { + // Swap arr[j] and arr[j + 1] + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + swapped = true; + } + } + if (!swapped) break; + } + } + + public static void main(String[] args) { + int[] arr = {64, 34, 25, 12, 22, 11, 90}; + bubbleSort(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/11.java b/Java/Medium/11.java new file mode 100644 index 00000000..511fc8d3 --- /dev/null +++ b/Java/Medium/11.java @@ -0,0 +1,22 @@ +// Question: Complete the function to check if two strings are anagrams (contain the same characters in any order). + +import java.util.Arrays; + +class Main { + public static boolean areAnagrams(String str1, String str2) { + if (str1.length() != str2.length()) return false; + + char[] arr1 = str1.toCharArray(); + char[] arr2 = str2.toCharArray(); + Arrays.sort(arr1); + Arrays.sort(arr2); + + return Arrays.equals(arr1, arr2); + } + + public static void main(String[] args) { + String str1 = "listen"; + String str2 = "silent"; + System.out.println("Are anagrams: " + areAnagrams(str1, str2)); + } +} diff --git a/Java/Medium/12.java b/Java/Medium/12.java new file mode 100644 index 00000000..2ac05a52 --- /dev/null +++ b/Java/Medium/12.java @@ -0,0 +1,13 @@ +// Question: Complete the function to find the factorial of a number using recursion. + +class Main { + public static int factorial(int n) { + if (n == 0 || n == 1) return 1; + return n * factorial(n - 1); + } + + public static void main(String[] args) { + int n = 5; + System.out.println("Factorial of " + n + ": " + factorial(n)); + } +} diff --git a/Java/Medium/13.java b/Java/Medium/13.java new file mode 100644 index 00000000..fb6aee7f --- /dev/null +++ b/Java/Medium/13.java @@ -0,0 +1,20 @@ +// Question: Complete the function to find the longest common prefix in an array of strings. + +class Main { + public static String longestCommonPrefix(String[] strs) { + if (strs == null || strs.length == 0) return ""; + String prefix = strs[0]; + for (int i = 1; i < strs.length; i++) { + while (strs[i].indexOf(prefix) != 0) { + prefix = prefix.substring(0, prefix.length() - 1); + if (prefix.isEmpty()) return ""; + } + } + return prefix; + } + + public static void main(String[] args) { + String[] strs = {"flower", "flow", "flight"}; + System.out.println("Longest common prefix: " + longestCommonPrefix(strs)); + } +} diff --git a/Java/Medium/14.java b/Java/Medium/14.java new file mode 100644 index 00000000..c66e323c --- /dev/null +++ b/Java/Medium/14.java @@ -0,0 +1,23 @@ +// Question: Complete the insertion sort algorithm to sort an array in ascending order. + +class Main { + public static void insertionSort(int[] arr) { + for (int i = 1; i < arr.length; i++) { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + } + + public static void main(String[] args) { + int[] arr = {12, 11, 13, 5, 6}; + insertionSort(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/15.java b/Java/Medium/15.java new file mode 100644 index 00000000..5e1c252b --- /dev/null +++ b/Java/Medium/15.java @@ -0,0 +1,23 @@ +// Question: Complete the function to reverse an array in place. + +class Main { + public static void reverseArray(int[] arr) { + int start = 0; + int end = arr.length - 1; + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5}; + reverseArray(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/16.java b/Java/Medium/16.java new file mode 100644 index 00000000..dab340f5 --- /dev/null +++ b/Java/Medium/16.java @@ -0,0 +1,29 @@ +// Question: Complete the function to rotate an array by `k` steps to the right. + +class Main { + public static void rotateArray(int[] arr, int k) { + k %= arr.length; + reverse(arr, 0, arr.length - 1); + reverse(arr, 0, k - 1); + reverse(arr, k, arr.length - 1); + } + + private static void reverse(int[] arr, int start, int end) { + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5, 6, 7}; + int k = 3; + rotateArray(arr, k); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/17.java b/Java/Medium/17.java new file mode 100644 index 00000000..8a388946 --- /dev/null +++ b/Java/Medium/17.java @@ -0,0 +1,23 @@ +// Question: Complete the function to find the first non-repeated character in a string. + +import java.util.HashMap; + +class Main { + public static char firstNonRepeatedChar(String str) { + HashMap charCount = new HashMap<>(); + for (char c : str.toCharArray()) { + charCount.put(c, charCount.getOrDefault(c, 0) + 1); + } + for (char c : str.toCharArray()) { + if (charCount.get(c) == 1) { + return c; + } + } + return '\0'; // return null character if no non-repeated character found + } + + public static void main(String[] args) { + String str = "swiss"; + System.out.println("First non-repeated character: " + firstNonRepeatedChar(str)); + } +} diff --git a/Java/Medium/18.java b/Java/Medium/18.java new file mode 100644 index 00000000..93093a51 --- /dev/null +++ b/Java/Medium/18.java @@ -0,0 +1,13 @@ +// Question: Complete the function to check if one string is a rotation of another string. + +class Main { + public static boolean areRotations(String str1, String str2) { + return (str1.length() == str2.length()) && ((str1 + str1).contains(str2)); + } + + public static void main(String[] args) { + String str1 = "ABCD"; + String str2 = "CDAB"; + System.out.println("Are rotations: " + areRotations(str1, str2)); + } +} diff --git a/Java/Medium/19.java b/Java/Medium/19.java new file mode 100644 index 00000000..a7adef71 --- /dev/null +++ b/Java/Medium/19.java @@ -0,0 +1,13 @@ +// Question: Complete the function to check if a given number is a power of two. + +class Main { + public static boolean isPowerOfTwo(int n) { + if (n <= 0) return false; + return (n & (n - 1)) == 0; + } + + public static void main(String[] args) { + int n = 16; + System.out.println("Is power of two: " + isPowerOfTwo(n)); + } +} diff --git a/Java/Medium/2.java b/Java/Medium/2.java new file mode 100644 index 00000000..bf3572a5 --- /dev/null +++ b/Java/Medium/2.java @@ -0,0 +1,49 @@ +// Question: Complete the merge sort algorithm to handle the case of sorting arrays of any size correctly. + +class Main { + public static void mergeSort(int[] arr) { + if (arr.length < 2) { + return; + } + int mid = arr.length / 2; + int[] left = new int[mid]; + int[] right = new int[arr.length - mid]; + + // Copy data to left and right arrays + for (int i = 0; i < mid; i++) { + left[i] = arr[i]; + } + for (int i = mid; i < arr.length; i++) { + right[i - mid] = arr[i]; + } + + mergeSort(left); + mergeSort(right); + merge(arr, left, right); + } + + public static void merge(int[] arr, int[] left, int[] right) { + int i = 0, j = 0, k = 0; + while (i < left.length && j < right.length) { + if (left[i] <= right[j]) { + arr[k++] = left[i++]; + } else { + arr[k++] = right[j++]; + } + } + while (i < left.length) { + arr[k++] = left[i++]; + } + while (j < right.length) { + arr[k++] = right[j++]; + } + } + + public static void main(String[] args) { + int[] arr = {5, 2, 4, 7, 1, 3, 6, 8}; + mergeSort(arr); + for (int num : arr) { + System.out.print(num + " "); + } + } +} diff --git a/Java/Medium/20.java b/Java/Medium/20.java new file mode 100644 index 00000000..f6b8ed7e --- /dev/null +++ b/Java/Medium/20.java @@ -0,0 +1,17 @@ +// Question: Complete the function to find the missing number in an array of size `n-1` where elements are from 1 to `n`. + +class Main { + public static int findMissingNumber(int[] arr, int n) { + int sum = n * (n + 1) / 2; + int actualSum = 0; + for (int num : arr) { + actualSum += num; + } + return sum - actualSum; + } + + public static void main(String[] args) { + int[] arr = {1, 2, 4, 5, 6}; + System.out.println("Missing number: " + findMissingNumber(arr, 6)); + } +} diff --git a/Java/Medium/21.java b/Java/Medium/21.java new file mode 100644 index 00000000..6b06f318 --- /dev/null +++ b/Java/Medium/21.java @@ -0,0 +1,35 @@ +// Question: Complete the function to merge two sorted arrays into one sorted array. + +class Main { + public static int[] mergeArrays(int[] arr1, int[] arr2) { + int[] merged = new int[arr1.length + arr2.length]; + int i = 0, j = 0, k = 0; + + while (i < arr1.length && j < arr2.length) { + if (arr1[i] < arr2[j]) { + merged[k++] = arr1[i++]; + } else { + merged[k++] = arr2[j++]; + } + } + + while (i < arr1.length) { + merged[k++] = arr1[i++]; + } + + while (j < arr2.length) { + merged[k++] = arr2[j++]; + } + + return merged; + } + + public static void main(String[] args) { + int[] arr1 = {1, 3, 5}; + int[] arr2 = {2, 4, 6}; + int[] merged = mergeArrays(arr1, arr2); + for (int value : merged) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/22.java b/Java/Medium/22.java new file mode 100644 index 00000000..bf82ca5e --- /dev/null +++ b/Java/Medium/22.java @@ -0,0 +1,18 @@ +// Question: Complete the function to find the largest element in an array. + +class Main { + public static int findLargest(int[] arr) { + int largest = arr[0]; + for (int value : arr) { + if (value > largest) { + largest = value; + } + } + return largest; + } + + public static void main(String[] args) { + int[] arr = {10, 20, 30, 5, 1}; + System.out.println("Largest element: " + findLargest(arr)); + } +} diff --git a/Java/Medium/23.java b/Java/Medium/23.java new file mode 100644 index 00000000..26bbcb44 --- /dev/null +++ b/Java/Medium/23.java @@ -0,0 +1,27 @@ +// Question: Complete the function to find all prime factors of a number. + +class Main { + public static void primeFactors(int n) { + while (n % 2 == 0) { + System.out.print(2 + " "); + n /= 2; + } + + for (int i = 3; i <= Math.sqrt(n); i += 2) { + while (n % i == 0) { + System.out.print(i + " "); + n /= i; + } + } + + if (n > 2) { + System.out.print(n); + } + } + + public static void main(String[] args) { + int n = 315; + System.out.println("Prime factors of " + n + ": "); + primeFactors(n); + } +} diff --git a/Java/Medium/24.java b/Java/Medium/24.java new file mode 100644 index 00000000..c362147b --- /dev/null +++ b/Java/Medium/24.java @@ -0,0 +1,17 @@ +// Question: Complete the function to check if an array is sorted in ascending order. + +class Main { + public static boolean isSorted(int[] arr) { + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i] > arr[i + 1]) { + return false; + } + } + return true; + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5}; + System.out.println("Is array sorted: " + isSorted(arr)); + } +} diff --git a/Java/Medium/25.java b/Java/Medium/25.java new file mode 100644 index 00000000..faf7fbd2 --- /dev/null +++ b/Java/Medium/25.java @@ -0,0 +1,25 @@ +// Question: Complete the function to find and print all duplicate elements in an array. + +import java.util.HashSet; + +class Main { + public static void findDuplicates(int[] arr) { + HashSet seen = new HashSet<>(); + HashSet duplicates = new HashSet<>(); + + for (int num : arr) { + if (!seen.add(num)) { + duplicates.add(num); + } + } + + for (int duplicate : duplicates) { + System.out.println("Duplicate: " + duplicate); + } + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5, 2, 3, 6}; + findDuplicates(arr); + } +} diff --git a/Java/Medium/26.java b/Java/Medium/26.java new file mode 100644 index 00000000..6fdda0aa --- /dev/null +++ b/Java/Medium/26.java @@ -0,0 +1,24 @@ +// Question: Complete the function to find the second largest element in an array. + +class Main { + public static int findSecondLargest(int[] arr) { + int largest = Integer.MIN_VALUE; + int secondLargest = Integer.MIN_VALUE; + + for (int value : arr) { + if (value > largest) { + secondLargest = largest; + largest = value; + } else if (value > secondLargest && value != largest) { + secondLargest = value; + } + } + + return secondLargest; + } + + public static void main(String[] args) { + int[] arr = {12, 35, 1, 10, 34, 1}; + System.out.println("Second largest element: " + findSecondLargest(arr)); + } +} diff --git a/Java/Medium/27.java b/Java/Medium/27.java new file mode 100644 index 00000000..250554f8 --- /dev/null +++ b/Java/Medium/27.java @@ -0,0 +1,24 @@ +// Question: Complete the function to find the intersection (common elements) of two arrays. + +import java.util.HashSet; + +class Main { + public static void findIntersection(int[] arr1, int[] arr2) { + HashSet set = new HashSet<>(); + for (int num : arr1) { + set.add(num); + } + + for (int num : arr2) { + if (set.contains(num)) { + System.out.println("Common element: " + num); + } + } + } + + public static void main(String[] args) { + int[] arr1 = {1, 2, 3, 4, 5}; + int[] arr2 = {4, 5, 6, 7, 8}; + findIntersection(arr1, arr2); + } +} diff --git a/Java/Medium/28.java b/Java/Medium/28.java new file mode 100644 index 00000000..0ea23cad --- /dev/null +++ b/Java/Medium/28.java @@ -0,0 +1,25 @@ +// Question: Complete the function to move all zeros to the end of an array without changing the order of non-zero elements. + +class Main { + public static void moveZerosToEnd(int[] arr) { + int nonZeroIndex = 0; + + for (int i = 0; i < arr.length; i++) { + if (arr[i] != 0) { + arr[nonZeroIndex++] = arr[i]; + } + } + + while (nonZeroIndex < arr.length) { + arr[nonZeroIndex++] = 0; + } + } + + public static void main(String[] args) { + int[] arr = {0, 1, 0, 3, 12}; + moveZerosToEnd(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/29.java b/Java/Medium/29.java new file mode 100644 index 00000000..2650fed9 --- /dev/null +++ b/Java/Medium/29.java @@ -0,0 +1,21 @@ +// Question: Complete the function to find the majority element in an array. A majority element appears more than n/2 times. + +import java.util.HashMap; + +class Main { + public static int findMajorityElement(int[] arr) { + HashMap countMap = new HashMap<>(); + for (int num : arr) { + countMap.put(num, countMap.getOrDefault(num, 0) + 1); + if (countMap.get(num) > arr.length / 2) { + return num; + } + } + return -1; // No majority element + } + + public static void main(String[] args) { + int[] arr = {2, 2, 1, 1, 1, 2, 2}; + System.out.println("Majority element: " + findMajorityElement(arr)); + } +} diff --git a/Java/Medium/3.java b/Java/Medium/3.java new file mode 100644 index 00000000..4a1de1d6 --- /dev/null +++ b/Java/Medium/3.java @@ -0,0 +1,15 @@ +// Question: Complete the Fibonacci sequence algorithm using recursion, but ensure it is optimized to handle large input values. + +class Main { + public static int fibonacci(int n) { + if (n <= 1) { + return n; + } + return fibonacci(n - 1) + fibonacci(n - 2); + } + + public static void main(String[] args) { + int n = 10; // Test with the 10th Fibonacci number + System.out.println("Fibonacci number " + n + ": " + fibonacci(n)); + } +} diff --git a/Java/Medium/30.java b/Java/Medium/30.java new file mode 100644 index 00000000..1a7c4b02 --- /dev/null +++ b/Java/Medium/30.java @@ -0,0 +1,22 @@ +// Question: Complete the function to find the Kth largest element in an unsorted array. + +import java.util.PriorityQueue; + +class Main { + public static int findKthLargest(int[] arr, int k) { + PriorityQueue minHeap = new PriorityQueue<>(); + for (int num : arr) { + minHeap.add(num); + if (minHeap.size() > k) { + minHeap.poll(); + } + } + return minHeap.peek(); + } + + public static void main(String[] args) { + int[] arr = {3, 2, 1, 5, 6, 4}; + int k = 2; + System.out.println("Kth largest element: " + findKthLargest(arr, k)); + } +} diff --git a/Java/Medium/31.java b/Java/Medium/31.java new file mode 100644 index 00000000..4b658f1c --- /dev/null +++ b/Java/Medium/31.java @@ -0,0 +1,32 @@ +// Question: Complete the function to check if a linked list has a cycle. + +class ListNode { + int val; + ListNode next; + ListNode(int x) { + val = x; + next = null; + } +} + +class Main { + public static boolean hasCycle(ListNode head) { + ListNode slow = head; + ListNode fast = head; + while (fast != null && fast.next != null) { + slow = slow.next; + fast = fast.next.next; + if (slow == fast) { + return true; + } + } + return false; + } + + public static void main(String[] args) { + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = head; // Creates a cycle + System.out.println("Has cycle: " + hasCycle(head)); + } +} diff --git a/Java/Medium/32.java b/Java/Medium/32.java new file mode 100644 index 00000000..67283893 --- /dev/null +++ b/Java/Medium/32.java @@ -0,0 +1,22 @@ +// Question: Complete the function to find and print all permutations of a string. + +class Main { + public static void permute(String str, String answer) { + if (str.length() == 0) { + System.out.println(answer); + return; + } + + for (int i = 0; i < str.length(); i++) { + char ch = str.charAt(i); + String leftSubstr = str.substring(0, i); + String rightSubstr = str.substring(i + 1); + permute(leftSubstr + rightSubstr, answer + ch); + } + } + + public static void main(String[] args) { + String str = "ABC"; + permute(str, ""); + } +} diff --git a/Java/Medium/33.java b/Java/Medium/33.java new file mode 100644 index 00000000..704ef3c6 --- /dev/null +++ b/Java/Medium/33.java @@ -0,0 +1,42 @@ +// Question: Complete the function to find the median of two sorted arrays. + +class Main { + public static double findMedianSortedArrays(int[] arr1, int[] arr2) { + int[] merged = mergeArrays(arr1, arr2); + int mid = merged.length / 2; + if (merged.length % 2 == 0) { + return (merged[mid - 1] + merged[mid]) / 2.0; + } else { + return merged[mid]; + } + } + + private static int[] mergeArrays(int[] arr1, int[] arr2) { + int[] merged = new int[arr1.length + arr2.length]; + int i = 0, j = 0, k = 0; + + while (i < arr1.length && j < arr2.length) { + if (arr1[i] < arr2[j]) { + merged[k++] = arr1[i++]; + } else { + merged[k++] = arr2[j++]; + } + } + + while (i < arr1.length) { + merged[k++] = arr1[i++]; + } + + while (j < arr2.length) { + merged[k++] = arr2[j++]; + } + + return merged; + } + + public static void main(String[] args) { + int[] arr1 = {1, 3}; + int[] arr2 = {2}; + System.out.println("Median: " + findMedianSortedArrays(arr1, arr2)); + } +} diff --git a/Java/Medium/34.java b/Java/Medium/34.java new file mode 100644 index 00000000..e21c629a --- /dev/null +++ b/Java/Medium/34.java @@ -0,0 +1,31 @@ +// Question: Complete the function to find the longest palindromic substring in a given string. + +class Main { + public static String longestPalindrome(String s) { + if (s == null || s.length() < 1) return ""; + int start = 0, end = 0; + for (int i = 0; i < s.length(); i++) { + int len1 = expandAroundCenter(s, i, i); + int len2 = expandAroundCenter(s, i, i + 1); + int len = Math.max(len1, len2); + if (len > end - start) { + start = i - (len - 1) / 2; + end = i + len / 2; + } + } + return s.substring(start, end + 1); + } + + private static int expandAroundCenter(String s, int left, int right) { + while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) { + left--; + right++; + } + return right - left - 1; + } + + public static void main(String[] args) { + String s = "babad"; + System.out.println("Longest palindromic substring: " + longestPalindrome(s)); + } +} diff --git a/Java/Medium/35.java b/Java/Medium/35.java new file mode 100644 index 00000000..0b898d3c --- /dev/null +++ b/Java/Medium/35.java @@ -0,0 +1,29 @@ +// Question: Complete the function to find and print all subsets of a given set of integers. + +import java.util.ArrayList; +import java.util.List; + +class Main { + public static List> subsets(int[] nums) { + List> result = new ArrayList<>(); + generateSubsets(0, nums, new ArrayList<>(), result); + return result; + } + + private static void generateSubsets(int index, int[] nums, List current, List> result) { + result.add(new ArrayList<>(current)); + for (int i = index; i < nums.length; i++) { + current.add(nums[i]); + generateSubsets(i + 1, nums, current, result); + current.remove(current.size() - 1); + } + } + + public static void main(String[] args) { + int[] nums = {1, 2, 3}; + List> subsets = subsets(nums); + for (List subset : subsets) { + System.out.println(subset); + } + } +} diff --git a/Java/Medium/36.java b/Java/Medium/36.java new file mode 100644 index 00000000..a056e175 --- /dev/null +++ b/Java/Medium/36.java @@ -0,0 +1,32 @@ +// Question: Complete the function to find the first missing positive integer in an unsorted array. + +class Main { + public static int firstMissingPositive(int[] nums) { + int n = nums.length; + + for (int i = 0; i < n; i++) { + while (nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] != nums[i]) { + swap(nums, i, nums[i] - 1); + } + } + + for (int i = 0; i < n; i++) { + if (nums[i] != i + 1) { + return i + 1; + } + } + + return n + 1; + } + + private static void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } + + public static void main(String[] args) { + int[] nums = {3, 4, -1, 1}; + System.out.println("First missing positive: " + firstMissingPositive(nums)); + } +} diff --git a/Java/Medium/37.java b/Java/Medium/37.java new file mode 100644 index 00000000..ea30338c --- /dev/null +++ b/Java/Medium/37.java @@ -0,0 +1,40 @@ +// Question: Complete the function to find all paths from the top-left corner to the bottom-right corner of a maze. + +import java.util.ArrayList; +import java.util.List; + +class Main { + public static List findAllPaths(int[][] maze, int x, int y, String path) { + List result = new ArrayList<>(); + if (x == maze.length - 1 && y == maze[0].length - 1) { + result.add(path); + return result; + } + + // Move down + if (x + 1 < maze.length && maze[x + 1][y] == 1) { + result.addAll(findAllPaths(maze, x + 1, y, path + "D")); + } + + // Move right + if (y + 1 < maze[0].length && maze[x][y + 1] == 1) { + result.addAll(findAllPaths(maze, x, y + 1, path + "R")); + } + + return result; + } + + public static void main(String[] args) { + int[][] maze = { + {1, 0, 0, 0}, + {1, 1, 0, 1}, + {0, 1, 0, 0}, + {1, 1, 1, 1} + }; + + List paths = findAllPaths(maze, 0, 0, ""); + for (String path : paths) { + System.out.println(path); + } + } +} diff --git a/Java/Medium/38.java b/Java/Medium/38.java new file mode 100644 index 00000000..ce81d1f9 --- /dev/null +++ b/Java/Medium/38.java @@ -0,0 +1,37 @@ +// Question: Complete the function to find the diameter (longest path) of a binary tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static int diameterOfBinaryTree(TreeNode root) { + int[] diameter = new int[1]; + height(root, diameter); + return diameter[0]; + } + + private static int height(TreeNode node, int[] diameter) { + if (node == null) return 0; + int leftHeight = height(node.left, diameter); + int rightHeight = height(node.right, diameter); + diameter[0] = Math.max(diameter[0], leftHeight + rightHeight); + return 1 + Math.max(leftHeight, rightHeight); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + + System.out.println("Diameter of the tree: " + diameterOfBinaryTree(root)); + } +} diff --git a/Java/Medium/39.java b/Java/Medium/39.java new file mode 100644 index 00000000..fbd202d7 --- /dev/null +++ b/Java/Medium/39.java @@ -0,0 +1,40 @@ +// Question: Complete the function to find the lowest common ancestor (LCA) of two nodes in a binary search tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null) return null; + + if (p.val < root.val && q.val < root.val) { + return lowestCommonAncestor(root.left, p, q); + } else if (p.val > root.val && q.val > root.val) { + return lowestCommonAncestor(root.right, p, q); + } else { + return root; + } + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(6); + root.left = new TreeNode(2); + root.right = new TreeNode(8); + root.left.left = new TreeNode(0); + root.left.right = new TreeNode(4); + root.right.left = new TreeNode(7); + root.right.right = new TreeNode(9); + + TreeNode p = root.left; // Node with value 2 + TreeNode q = root.right; // Node with value 8 + + System.out.println("Lowest common ancestor: " + lowestCommonAncestor(root, p, q).val); + } +} diff --git a/Java/Medium/4.java b/Java/Medium/4.java new file mode 100644 index 00000000..5bdf498d --- /dev/null +++ b/Java/Medium/4.java @@ -0,0 +1,17 @@ +// Question: Complete the code to find the maximum sum of a contiguous subarray within a one-dimensional array of numbers using Kadane’s Algorithm. + +class Main { + public static int maxSubArray(int[] arr) { + int maxSoFar = arr[0], maxEndingHere = arr[0]; + for (int i = 1; i < arr.length; i++) { + maxEndingHere = Math.max(arr[i], maxEndingHere + arr[i]); + maxSoFar = Math.max(maxSoFar, maxEndingHere); + } + return maxSoFar; + } + + public static void main(String[] args) { + int[] arr = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; + System.out.println("Maximum subarray sum: " + maxSubArray(arr)); + } +} diff --git a/Java/Medium/40.java b/Java/Medium/40.java new file mode 100644 index 00000000..52b82484 --- /dev/null +++ b/Java/Medium/40.java @@ -0,0 +1,28 @@ +// Question: Complete the function to find the maximum depth (height) of a binary tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static int maxDepth(TreeNode root) { + if (root == null) return 0; + return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + + System.out.println("Maximum depth of the tree: " + maxDepth(root)); + } +} diff --git a/Java/Medium/41.java b/Java/Medium/41.java new file mode 100644 index 00000000..78102891 --- /dev/null +++ b/Java/Medium/41.java @@ -0,0 +1,29 @@ +// Question: Complete the function to perform inorder traversal of a binary tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static void inorderTraversal(TreeNode root) { + if (root == null) return; + inorderTraversal(root.left); + System.out.print(root.val + " "); + inorderTraversal(root.right); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.right = new TreeNode(2); + root.right.left = new TreeNode(3); + + System.out.print("Inorder traversal: "); + inorderTraversal(root); + } +} diff --git a/Java/Medium/42.java b/Java/Medium/42.java new file mode 100644 index 00000000..2b7aadcb --- /dev/null +++ b/Java/Medium/42.java @@ -0,0 +1,36 @@ +// Question: Complete the function to perform breadth-first search (BFS) on a graph. + +import java.util.LinkedList; +import java.util.Queue; + +class Main { + public static void bfs(int[][] graph, int start) { + boolean[] visited = new boolean[graph.length]; + Queue queue = new LinkedList<>(); + queue.add(start); + visited[start] = true; + + while (!queue.isEmpty()) { + int node = queue.poll(); + System.out.print(node + " "); + + for (int i = 0; i < graph[node].length; i++) { + if (graph[node][i] == 1 && !visited[i]) { + queue.add(i); + visited[i] = true; + } + } + } + } + + public static void main(String[] args) { + int[][] graph = { + {0, 1, 1, 0}, + {1, 0, 1, 1}, + {1, 1, 0, 1}, + {0, 1, 1, 0} + }; + System.out.print("BFS: "); + bfs(graph, 0); + } +} diff --git a/Java/Medium/43.java b/Java/Medium/43.java new file mode 100644 index 00000000..f4c8419a --- /dev/null +++ b/Java/Medium/43.java @@ -0,0 +1,26 @@ +// Question: Complete the function to perform depth-first search (DFS) on a graph. + +class Main { + public static void dfs(int[][] graph, int start, boolean[] visited) { + visited[start] = true; + System.out.print(start + " "); + + for (int i = 0; i < graph[start].length; i++) { + if (graph[start][i] == 1 && !visited[i]) { + dfs(graph, i, visited); + } + } + } + + public static void main(String[] args) { + int[][] graph = { + {0, 1, 1, 0}, + {1, 0, 1, 1}, + {1, 1, 0, 1}, + {0, 1, 1, 0} + }; + boolean[] visited = new boolean[graph.length]; + System.out.print("DFS: "); + dfs(graph, 0, visited); + } +} diff --git a/Java/Medium/44.java b/Java/Medium/44.java new file mode 100644 index 00000000..6cbf23e4 --- /dev/null +++ b/Java/Medium/44.java @@ -0,0 +1,19 @@ +// Question: Complete the function to find the Nth Fibonacci number using dynamic programming. + +class Main { + public static int fibonacciDP(int n) { + if (n <= 1) return n; + int[] fib = new int[n + 1]; + fib[0] = 0; + fib[1] = 1; + for (int i = 2; i <= n; i++) { + fib[i] = fib[i - 1] + fib[i - 2]; + } + return fib[n]; + } + + public static void main(String[] args) { + int n = 10; + System.out.println("Fibonacci number " + n + ": " + fibonacciDP(n)); + } +} diff --git a/Java/Medium/45.java b/Java/Medium/45.java new file mode 100644 index 00000000..34472605 --- /dev/null +++ b/Java/Medium/45.java @@ -0,0 +1,34 @@ +// Question: Complete the function to check if a binary tree is symmetric (a mirror of itself). + +class TreeNode { + int val; + TreeNode left, right; + TreeNode(int x) { + val = x; + } +} + +class Main { + public static boolean isSymmetric(TreeNode root) { + if (root == null) return true; + return isMirror(root.left, root.right); + } + + private static boolean isMirror(TreeNode t1, TreeNode t2) { + if (t1 == null && t2 == null) return true; + if (t1 == null || t2 == null) return false; + return (t1.val == t2.val) && isMirror(t1.left, t2.right) && isMirror(t1.right, t2.left); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(2); + root.left.left = new TreeNode(3); + root.left.right = new TreeNode(4); + root.right.left = new TreeNode(4); + root.right.right = new TreeNode(3); + + System.out.println("Is symmetric: " + isSymmetric(root)); + } +} diff --git a/Java/Medium/46.java b/Java/Medium/46.java new file mode 100644 index 00000000..68a2722e --- /dev/null +++ b/Java/Medium/46.java @@ -0,0 +1,36 @@ +// Question: Complete the function to count the number of islands in a 2D grid (using DFS). + +class Main { + public static int numIslands(char[][] grid) { + if (grid == null || grid.length == 0) return 0; + int numIslands = 0; + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[0].length; j++) { + if (grid[i][j] == '1') { + numIslands += dfs(grid, i, j); + } + } + } + return numIslands; + } + + private static int dfs(char[][] grid, int i, int j) { + if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] == '0') return 0; + grid[i][j] = '0'; // Mark visited + dfs(grid, i - 1, j); + dfs(grid, i + 1, j); + dfs(grid, i, j - 1); + dfs(grid, i, j + 1); + return 1; + } + + public static void main(String[] args) { + char[][] grid = { + {'1', '1', '0', '0', '0'}, + {'1', '1', '0', '0', '0'}, + {'0', '0', '1', '0', '0'}, + {'0', '0', '0', '1', '1'} + }; + System.out.println("Number of islands: " + numIslands(grid)); + } +} diff --git a/Java/Medium/47.java b/Java/Medium/47.java new file mode 100644 index 00000000..0a27a665 --- /dev/null +++ b/Java/Medium/47.java @@ -0,0 +1,32 @@ +// Question: Complete the function to find the minimum path sum from the top-left corner to the bottom-right corner of a grid. + +class Main { + public static int minPathSum(int[][] grid) { + int rows = grid.length; + int cols = grid[0].length; + + for (int i = 1; i < rows; i++) { + grid[i][0] += grid[i - 1][0]; + } + for (int j = 1; j < cols; j++) { + grid[0][j] += grid[0][j - 1]; + } + + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + grid[i][j] += Math.min(grid[i - 1][j], grid[i][j - 1]); + } + } + + return grid[rows - 1][cols - 1]; + } + + public static void main(String[] args) { + int[][] grid = { + {1, 3, 1}, + {1, 5, 1}, + {4, 2, 1} + }; + System.out.println("Minimum path sum: " + minPathSum(grid)); + } +} diff --git a/Java/Medium/48.java b/Java/Medium/48.java new file mode 100644 index 00000000..5e24118e --- /dev/null +++ b/Java/Medium/48.java @@ -0,0 +1,26 @@ +// Question: Complete the function to solve the 0/1 Knapsack problem using dynamic programming. + +class Main { + public static int knapsack(int[] weights, int[] values, int capacity) { + int n = weights.length; + int[][] dp = new int[n + 1][capacity + 1]; + + for (int i = 1; i <= n; i++) { + for (int w = 0; w <= capacity; w++) { + if (weights[i - 1] <= w) { + dp[i][w] = Math.max(dp[i - 1][w], values[i - 1] + dp[i - 1][w - weights[i - 1]]); + } else { + dp[i][w] = dp[i - 1][w]; + } + } + } + return dp[n][capacity]; + } + + public static void main(String[] args) { + int[] weights = {1, 3, 4, 5}; + int[] values = {1, 4, 5, 7}; + int capacity = 7; + System.out.println("Maximum value: " + knapsack(weights, values, capacity)); + } +} diff --git a/Java/Medium/49.java b/Java/Medium/49.java new file mode 100644 index 00000000..657f1063 --- /dev/null +++ b/Java/Medium/49.java @@ -0,0 +1,33 @@ +// Question: Complete the function to convert a binary tree into its mirror. + +class TreeNode { + int val; + TreeNode left, right; + TreeNode(int x) { + val = x; + } +} + +class Main { + public static TreeNode mirror(TreeNode root) { + if (root == null) return null; + TreeNode temp = root.left; + root.left = root.right; + root.right = temp; + + mirror(root.left); + mirror(root.right); + return root; + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + + root = mirror(root); + System.out.println("Root of mirrored tree: " + root.val); + } +} diff --git a/Java/Medium/5.java b/Java/Medium/5.java new file mode 100644 index 00000000..bdf6a929 --- /dev/null +++ b/Java/Medium/5.java @@ -0,0 +1,28 @@ +// Question: Complete the code to find and print all prime numbers less than or equal to a given number N. + +class Main { + public static boolean isPrime(int n) { + if (n <= 1) { + return false; + } + for (int i = 2; i * i <= n; i++) { + if (n % i == 0) { + return false; + } + } + return true; + } + + public static void printPrimes(int n) { + for (int i = 2; i <= n; i++) { + if (isPrime(i)) { + System.out.print(i + " "); + } + } + } + + public static void main(String[] args) { + int n = 30; // Find primes up to 30 + printPrimes(n); + } +} diff --git a/Java/Medium/50.java b/Java/Medium/50.java new file mode 100644 index 00000000..c508d501 --- /dev/null +++ b/Java/Medium/50.java @@ -0,0 +1,32 @@ +// Question: Complete the function to find the longest increasing subsequence in an array. + +import java.util.Arrays; + +class Main { + public static int lengthOfLIS(int[] nums) { + if (nums.length == 0) return 0; + + int[] dp = new int[nums.length]; + Arrays.fill(dp, 1); + + for (int i = 1; i < nums.length; i++) { + for (int j = 0; j < i; j++) { + if (nums[i] > nums[j]) { + dp[i] = Math.max(dp[i], dp[j] + 1); + } + } + } + + int maxLength = 0; + for (int length : dp) { + maxLength = Math.max(maxLength, length); + } + + return maxLength; + } + + public static void main(String[] args) { + int[] nums = {10, 9, 2, 5, 3, 7, 101, 18}; + System.out.println("Length of LIS: " + lengthOfLIS(nums)); + } +} diff --git a/Java/Medium/6.java b/Java/Medium/6.java new file mode 100644 index 00000000..5b87361e --- /dev/null +++ b/Java/Medium/6.java @@ -0,0 +1,20 @@ +// Question: Complete the function to check if a given string is a palindrome (the same forwards and backwards). + +class Main { + public static boolean isPalindrome(String str) { + int left = 0, right = str.length() - 1; + while (left < right) { + if (str.charAt(left) != str.charAt(right)) { + return false; + } + left++; + right--; + } + return true; + } + + public static void main(String[] args) { + String str = "racecar"; + System.out.println("Is palindrome: " + isPalindrome(str)); + } +} diff --git a/Java/Medium/7.java b/Java/Medium/7.java new file mode 100644 index 00000000..9e283f19 --- /dev/null +++ b/Java/Medium/7.java @@ -0,0 +1,17 @@ +// Question: Complete the function to calculate the greatest common divisor (GCD) of two numbers using Euclid's algorithm. + +class Main { + public static int gcd(int a, int b) { + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; + } + + public static void main(String[] args) { + int a = 56, b = 98; + System.out.println("GCD: " + gcd(a, b)); + } +} diff --git a/Java/Medium/8.java b/Java/Medium/8.java new file mode 100644 index 00000000..00beecb3 --- /dev/null +++ b/Java/Medium/8.java @@ -0,0 +1,36 @@ +// Question: Complete the function to reverse a singly linked list. + +class ListNode { + int val; + ListNode next; + ListNode(int x) { + val = x; + next = null; + } +} + +class Main { + public static ListNode reverseList(ListNode head) { + ListNode prev = null; + ListNode current = head; + while (current != null) { + ListNode nextNode = current.next; + current.next = prev; + prev = current; + current = nextNode; + } + return prev; + } + + public static void main(String[] args) { + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + + head = reverseList(head); + while (head != null) { + System.out.print(head.val + " "); + head = head.next; + } + } +} diff --git a/Java/Medium/9.java b/Java/Medium/9.java new file mode 100644 index 00000000..ceaeb64e --- /dev/null +++ b/Java/Medium/9.java @@ -0,0 +1,57 @@ +// Question: Complete the function to count inversions in an array. An inversion is when a pair of elements are out of order. + +class Main { + public static int countInversions(int[] arr) { + return mergeSortAndCount(arr, 0, arr.length - 1); + } + + private static int mergeSortAndCount(int[] arr, int left, int right) { + int count = 0; + if (left < right) { + int mid = (left + right) / 2; + + count += mergeSortAndCount(arr, left, mid); + count += mergeSortAndCount(arr, mid + 1, right); + count += mergeAndCount(arr, left, mid, right); + } + return count; + } + + private static int mergeAndCount(int[] arr, int left, int mid, int right) { + int[] leftArr = new int[mid - left + 1]; + int[] rightArr = new int[right - mid]; + + for (int i = 0; i < leftArr.length; i++) { + leftArr[i] = arr[left + i]; + } + for (int i = 0; i < rightArr.length; i++) { + rightArr[i] = arr[mid + 1 + i]; + } + + int i = 0, j = 0, k = left, swaps = 0; + + while (i < leftArr.length && j < rightArr.length) { + if (leftArr[i] <= rightArr[j]) { + arr[k++] = leftArr[i++]; + } else { + arr[k++] = rightArr[j++]; + swaps += (mid + 1) - (left + i); + } + } + + while (i < leftArr.length) { + arr[k++] = leftArr[i++]; + } + + while (j < rightArr.length) { + arr[k++] = rightArr[j++]; + } + + return swaps; + } + + public static void main(String[] args) { + int[] arr = {1, 20, 6, 4, 5}; + System.out.println("Number of inversions: " + countInversions(arr)); + } +} From 498cd7865c1b213c73bbeb234cea1558b229bff4 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 18:33:44 +0530 Subject: [PATCH 27/62] Create temp.txt --- C/Easy/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 C/Easy/temp.txt diff --git a/C/Easy/temp.txt b/C/Easy/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/C/Easy/temp.txt @@ -0,0 +1 @@ + From b83a41a24dc9ec629ae88840c2bd4345b09699d3 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 18:34:19 +0530 Subject: [PATCH 28/62] Create temp.txt --- C/Medium/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 C/Medium/temp.txt diff --git a/C/Medium/temp.txt b/C/Medium/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/C/Medium/temp.txt @@ -0,0 +1 @@ + From 4f238b68f9765ab2d8a14c31c836673d7f303438 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 18:34:35 +0530 Subject: [PATCH 29/62] Create temp.txt --- C/Hard/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 C/Hard/temp.txt diff --git a/C/Hard/temp.txt b/C/Hard/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/C/Hard/temp.txt @@ -0,0 +1 @@ + From cf04f2f0b572c3e1204e7ec94142a879c90cef7e Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 13:18:58 +0000 Subject: [PATCH 30/62] Added C Challenges --- C/Easy/1.c | 8 +++++++ C/Easy/10.c | 9 ++++++++ C/Easy/11.c | 12 ++++++++++ C/Easy/13.c | 11 +++++++++ C/Easy/14.c | 22 ++++++++++++++++++ C/Easy/15.c | 11 +++++++++ C/Easy/16.c | 11 +++++++++ C/Easy/17.c | 8 +++++++ C/Easy/18.c | 12 ++++++++++ C/Easy/19.c | 6 +++++ C/Easy/2.c | 7 ++++++ C/Easy/20.c | 5 +++++ C/Easy/21.c | 6 +++++ C/Easy/22.c | 8 +++++++ C/Easy/23.c | 8 +++++++ C/Easy/24.c | 16 +++++++++++++ C/Easy/25.c | 7 ++++++ C/Easy/26.c | 9 ++++++++ C/Easy/27.c | 12 ++++++++++ C/Easy/28.c | 15 +++++++++++++ C/Easy/29.c | 24 ++++++++++++++++++++ C/Easy/3.c | 14 ++++++++++++ C/Easy/30.c | 26 +++++++++++++++++++++ C/Easy/31.c | 9 ++++++++ C/Easy/32.c | 6 +++++ C/Easy/33.c | 8 +++++++ C/Easy/34.c | 14 ++++++++++++ C/Easy/35.c | 26 +++++++++++++++++++++ C/Easy/36.c | 12 ++++++++++ C/Easy/37.c | 14 ++++++++++++ C/Easy/38.c | 0 C/Easy/39.c | 6 +++++ C/Easy/4.c | 6 +++++ C/Easy/40.c | 18 +++++++++++++++ C/Easy/41.c | 13 +++++++++++ C/Easy/42.c | 10 +++++++++ C/Easy/43.c | 13 +++++++++++ C/Easy/44.c | 22 ++++++++++++++++++ C/Easy/45.c | 8 +++++++ C/Easy/46.c | 12 ++++++++++ C/Easy/47.c | 10 +++++++++ C/Easy/48.c | 14 ++++++++++++ C/Easy/49.c | 14 ++++++++++++ C/Easy/5.c | 7 ++++++ C/Easy/50.c | 10 +++++++++ C/Easy/51.c | 8 +++++++ C/Easy/52.c | 7 ++++++ C/Easy/53.c | 10 +++++++++ C/Easy/54.c | 7 ++++++ C/Easy/55.c | 8 +++++++ C/Easy/56.c | 9 ++++++++ C/Easy/6.c | 9 ++++++++ C/Easy/7.c | 8 +++++++ C/Easy/8.c | 14 ++++++++++++ C/Easy/9.c | 11 +++++++++ C/{Easy/temp.txt => Hard/.gitkeep} | 0 C/Hard/temp.txt | 1 - C/Medium/1.c | 24 ++++++++++++++++++++ C/Medium/10.c | 26 +++++++++++++++++++++ C/Medium/11.c | 29 ++++++++++++++++++++++++ C/Medium/12.c | 27 ++++++++++++++++++++++ C/Medium/13.c | 25 +++++++++++++++++++++ C/Medium/14.c | 20 +++++++++++++++++ C/Medium/15.c | 19 ++++++++++++++++ C/Medium/16.c | 36 ++++++++++++++++++++++++++++++ C/Medium/17.c | 24 ++++++++++++++++++++ C/Medium/18.c | 21 +++++++++++++++++ C/Medium/19.c | 21 +++++++++++++++++ C/Medium/2.c | 14 ++++++++++++ C/Medium/20.c | 19 ++++++++++++++++ C/Medium/21.c | 24 ++++++++++++++++++++ C/Medium/22.c | 6 +++++ C/Medium/23.c | 10 +++++++++ C/Medium/24.c | 6 +++++ C/Medium/25.c | 5 +++++ C/Medium/26.c | 7 ++++++ C/Medium/27.c | 9 ++++++++ C/Medium/28.c | 6 +++++ C/Medium/29.c | 8 +++++++ C/Medium/3.c | 12 ++++++++++ C/Medium/30.c | 13 +++++++++++ C/Medium/31.c | 21 +++++++++++++++++ C/Medium/32.c | 30 +++++++++++++++++++++++++ C/Medium/33.c | 21 +++++++++++++++++ C/Medium/34.c | 17 ++++++++++++++ C/Medium/35.c | 27 ++++++++++++++++++++++ C/Medium/36.c | 28 +++++++++++++++++++++++ C/Medium/37.c | 17 ++++++++++++++ C/Medium/38.c | 25 +++++++++++++++++++++ C/Medium/39.c | 21 +++++++++++++++++ C/Medium/4.c | 14 ++++++++++++ C/Medium/40.c | 13 +++++++++++ C/Medium/41.c | 25 +++++++++++++++++++++ C/Medium/42.c | 11 +++++++++ C/Medium/43.c | 10 +++++++++ C/Medium/44.c | 9 ++++++++ C/Medium/45.c | 7 ++++++ C/Medium/46.c | 10 +++++++++ C/Medium/47.c | 18 +++++++++++++++ C/Medium/48.c | 10 +++++++++ C/Medium/49.c | 15 +++++++++++++ C/Medium/5.c | 13 +++++++++++ C/Medium/50.c | 8 +++++++ C/Medium/51.c | 10 +++++++++ C/Medium/52.c | 7 ++++++ C/Medium/6.c | 13 +++++++++++ C/Medium/7.c | 21 +++++++++++++++++ C/Medium/8.c | 26 +++++++++++++++++++++ C/Medium/9.c | 36 ++++++++++++++++++++++++++++++ C/Medium/temp.txt | 1 - C/temp.txt | 1 - 111 files changed, 1504 insertions(+), 3 deletions(-) create mode 100644 C/Easy/1.c create mode 100644 C/Easy/10.c create mode 100644 C/Easy/11.c create mode 100644 C/Easy/13.c create mode 100644 C/Easy/14.c create mode 100644 C/Easy/15.c create mode 100644 C/Easy/16.c create mode 100644 C/Easy/17.c create mode 100644 C/Easy/18.c create mode 100644 C/Easy/19.c create mode 100644 C/Easy/2.c create mode 100644 C/Easy/20.c create mode 100644 C/Easy/21.c create mode 100644 C/Easy/22.c create mode 100644 C/Easy/23.c create mode 100644 C/Easy/24.c create mode 100644 C/Easy/25.c create mode 100644 C/Easy/26.c create mode 100644 C/Easy/27.c create mode 100644 C/Easy/28.c create mode 100644 C/Easy/29.c create mode 100644 C/Easy/3.c create mode 100644 C/Easy/30.c create mode 100644 C/Easy/31.c create mode 100644 C/Easy/32.c create mode 100644 C/Easy/33.c create mode 100644 C/Easy/34.c create mode 100644 C/Easy/35.c create mode 100644 C/Easy/36.c create mode 100644 C/Easy/37.c create mode 100644 C/Easy/38.c create mode 100644 C/Easy/39.c create mode 100644 C/Easy/4.c create mode 100644 C/Easy/40.c create mode 100644 C/Easy/41.c create mode 100644 C/Easy/42.c create mode 100644 C/Easy/43.c create mode 100644 C/Easy/44.c create mode 100644 C/Easy/45.c create mode 100644 C/Easy/46.c create mode 100644 C/Easy/47.c create mode 100644 C/Easy/48.c create mode 100644 C/Easy/49.c create mode 100644 C/Easy/5.c create mode 100644 C/Easy/50.c create mode 100644 C/Easy/51.c create mode 100644 C/Easy/52.c create mode 100644 C/Easy/53.c create mode 100644 C/Easy/54.c create mode 100644 C/Easy/55.c create mode 100644 C/Easy/56.c create mode 100644 C/Easy/6.c create mode 100644 C/Easy/7.c create mode 100644 C/Easy/8.c create mode 100644 C/Easy/9.c rename C/{Easy/temp.txt => Hard/.gitkeep} (100%) delete mode 100644 C/Hard/temp.txt create mode 100644 C/Medium/1.c create mode 100644 C/Medium/10.c create mode 100644 C/Medium/11.c create mode 100644 C/Medium/12.c create mode 100644 C/Medium/13.c create mode 100644 C/Medium/14.c create mode 100644 C/Medium/15.c create mode 100644 C/Medium/16.c create mode 100644 C/Medium/17.c create mode 100644 C/Medium/18.c create mode 100644 C/Medium/19.c create mode 100644 C/Medium/2.c create mode 100644 C/Medium/20.c create mode 100644 C/Medium/21.c create mode 100644 C/Medium/22.c create mode 100644 C/Medium/23.c create mode 100644 C/Medium/24.c create mode 100644 C/Medium/25.c create mode 100644 C/Medium/26.c create mode 100644 C/Medium/27.c create mode 100644 C/Medium/28.c create mode 100644 C/Medium/29.c create mode 100644 C/Medium/3.c create mode 100644 C/Medium/30.c create mode 100644 C/Medium/31.c create mode 100644 C/Medium/32.c create mode 100644 C/Medium/33.c create mode 100644 C/Medium/34.c create mode 100644 C/Medium/35.c create mode 100644 C/Medium/36.c create mode 100644 C/Medium/37.c create mode 100644 C/Medium/38.c create mode 100644 C/Medium/39.c create mode 100644 C/Medium/4.c create mode 100644 C/Medium/40.c create mode 100644 C/Medium/41.c create mode 100644 C/Medium/42.c create mode 100644 C/Medium/43.c create mode 100644 C/Medium/44.c create mode 100644 C/Medium/45.c create mode 100644 C/Medium/46.c create mode 100644 C/Medium/47.c create mode 100644 C/Medium/48.c create mode 100644 C/Medium/49.c create mode 100644 C/Medium/5.c create mode 100644 C/Medium/50.c create mode 100644 C/Medium/51.c create mode 100644 C/Medium/52.c create mode 100644 C/Medium/6.c create mode 100644 C/Medium/7.c create mode 100644 C/Medium/8.c create mode 100644 C/Medium/9.c delete mode 100644 C/Medium/temp.txt delete mode 100644 C/temp.txt diff --git a/C/Easy/1.c b/C/Easy/1.c new file mode 100644 index 00000000..b75bd447 --- /dev/null +++ b/C/Easy/1.c @@ -0,0 +1,8 @@ +#include + +int main() { + int arr[5]; + arr = {1, 2, 3, 4, 5}; + printf("%d", arr[2]); + return 0; +} \ No newline at end of file diff --git a/C/Easy/10.c b/C/Easy/10.c new file mode 100644 index 00000000..968653ed --- /dev/null +++ b/C/Easy/10.c @@ -0,0 +1,9 @@ +#include + +int main() { + int num; + printf("Enter a number: "); + scanf("%d", num); + printf("You entered: %d\n", num); + return 0; +} \ No newline at end of file diff --git a/C/Easy/11.c b/C/Easy/11.c new file mode 100644 index 00000000..285944a3 --- /dev/null +++ b/C/Easy/11.c @@ -0,0 +1,12 @@ + +#include + +int main() { + int arr[] = {1, 2, 3, 4, 5}; + int size = sizeof(arr) / sizeof(int); + for (int i = 0; i <= size; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + return 0; +} \ No newline at end of file diff --git a/C/Easy/13.c b/C/Easy/13.c new file mode 100644 index 00000000..de17f81f --- /dev/null +++ b/C/Easy/13.c @@ -0,0 +1,11 @@ +#include + +int main() { + int a = 10; + if (a = 5) { + printf("a is 5"); + } else { + printf("a is not 5"); + } + return 0; +} \ No newline at end of file diff --git a/C/Easy/14.c b/C/Easy/14.c new file mode 100644 index 00000000..9b0b564a --- /dev/null +++ b/C/Easy/14.c @@ -0,0 +1,22 @@ +#include + +struct person { + char name[20]; + int age; +}; + +void display(struct person p); + +int main() { + struct person p1; + printf("Enter name: "); + scanf("%s", p1.name); + printf("Enter age: "); + scanf("%d", p1.age); + display(p1); + return 0; +} + +void display(struct person p) { + printf("Name: %s, Age: %d\n", p.name, p.age); +} \ No newline at end of file diff --git a/C/Easy/15.c b/C/Easy/15.c new file mode 100644 index 00000000..4a0e7a15 --- /dev/null +++ b/C/Easy/15.c @@ -0,0 +1,11 @@ + +#include + +int main() { + printMessage(); + return 0; +} + +void printMessage() { + printf("Hello, World!\n"); +} \ No newline at end of file diff --git a/C/Easy/16.c b/C/Easy/16.c new file mode 100644 index 00000000..3a64d63b --- /dev/null +++ b/C/Easy/16.c @@ -0,0 +1,11 @@ +#include + +int main() { + int n = 5; + int arr[n]; // Error: variable-length array declared without a constant size + for (int i = 0; i < n; i++) { + arr[i] = i; + } + printf("%d", arr[3]); + return 0; +} \ No newline at end of file diff --git a/C/Easy/17.c b/C/Easy/17.c new file mode 100644 index 00000000..d1f1d14c --- /dev/null +++ b/C/Easy/17.c @@ -0,0 +1,8 @@ +#include + +int main() { + int a = 10, *p; + p = &a; + printf("Value of a: %d", *a); // Wrong pointer dereference + return 0; +} \ No newline at end of file diff --git a/C/Easy/18.c b/C/Easy/18.c new file mode 100644 index 00000000..0c44bb4c --- /dev/null +++ b/C/Easy/18.c @@ -0,0 +1,12 @@ +#include + +struct student { + char name[20]; + int age; +}; + +int main() { + struct student s[3] = {{"John", 20}, {"Alice", 22}, {"Bob", 23}}; + printf("Name: %s, Age: %d", s[4].name, s[4].age); + return 0; +} \ No newline at end of file diff --git a/C/Easy/19.c b/C/Easy/19.c new file mode 100644 index 00000000..37274238 --- /dev/null +++ b/C/Easy/19.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, World!"); + // Missing return statement +} \ No newline at end of file diff --git a/C/Easy/2.c b/C/Easy/2.c new file mode 100644 index 00000000..5e6f55e3 --- /dev/null +++ b/C/Easy/2.c @@ -0,0 +1,7 @@ +int main() { + int a = 10; + double b = 5.5; + int c = a + b; + printf("The sum of a and b is %d", c); + return 0; +} diff --git a/C/Easy/20.c b/C/Easy/20.c new file mode 100644 index 00000000..a1af93e5 --- /dev/null +++ b/C/Easy/20.c @@ -0,0 +1,5 @@ +#include +int main() { + printf(Hello, World); + return 0; +} diff --git a/C/Easy/21.c b/C/Easy/21.c new file mode 100644 index 00000000..107aabce --- /dev/null +++ b/C/Easy/21.c @@ -0,0 +1,6 @@ +#include +int main() { + int a = 5; + printf("%f", a); + return 0; +} diff --git a/C/Easy/22.c b/C/Easy/22.c new file mode 100644 index 00000000..9a392f95 --- /dev/null +++ b/C/Easy/22.c @@ -0,0 +1,8 @@ +#include +int main() { + int a = 5; + a *+ 1; + printf("%d", a); + return 0; +} +  diff --git a/C/Easy/23.c b/C/Easy/23.c new file mode 100644 index 00000000..84515352 --- /dev/null +++ b/C/Easy/23.c @@ -0,0 +1,8 @@ +#include + + { + int arr[3] = {1, 2, 3}; + for (int i = 0; i < 3; i++) + printf("%d ", arr[i]); + return 0; +} diff --git a/C/Easy/24.c b/C/Easy/24.c new file mode 100644 index 00000000..6c5437db --- /dev/null +++ b/C/Easy/24.c @@ -0,0 +1,16 @@ +#include +#include +int main() { + int a; + + printf("Enter your age: "); + scanf("%d", &a); + + if (a >= 18) { + printf("You are eligible for a license.\n"); + } else { + printf("Sorry! You are not eligible for a license.\n"); + } + + return 0; +} diff --git a/C/Easy/25.c b/C/Easy/25.c new file mode 100644 index 00000000..7b69e8eb --- /dev/null +++ b/C/Easy/25.c @@ -0,0 +1,7 @@ +#include + +int main() { + int x = "hello"; + printf("%d", x); + return 0; +} diff --git a/C/Easy/26.c b/C/Easy/26.c new file mode 100644 index 00000000..1d29601f --- /dev/null +++ b/C/Easy/26.c @@ -0,0 +1,9 @@ +#include + +int main() { + int x; + scanf("%d", &x); + char c; + scanf("%c", &c); + return 0; +} diff --git a/C/Easy/27.c b/C/Easy/27.c new file mode 100644 index 00000000..f2e07806 --- /dev/null +++ b/C/Easy/27.c @@ -0,0 +1,12 @@ +#include + +int main() { + int i, j + for (i = 1; i <= 5; i++) { + for (j = 1; j <= i; j++) { + printf("* "); + } + printf("\n"); + } + return 0; +} diff --git a/C/Easy/28.c b/C/Easy/28.c new file mode 100644 index 00000000..17e07e18 --- /dev/null +++ b/C/Easy/28.c @@ -0,0 +1,15 @@ +#include + +int main() { + int numbers[5]; + int i; + + for (i = 0; i < 5; i++) { + scanf("%d", &numbers[i]) + } + + printf("The array elements are:\n"); + + return 0; +} + diff --git a/C/Easy/29.c b/C/Easy/29.c new file mode 100644 index 00000000..86676cf9 --- /dev/null +++ b/C/Easy/29.c @@ -0,0 +1,24 @@ +#include +#include + +struct Node { + int data; + struct Node* next +}; + +int main() { + struct Node* head = NULL; + struct Node* second = NULL; + + head = (struct Node*)malloc(sizeof(struct Node)); + second = (struct Node*)malloc(sizeof(struct Node)); + + head->data = 1; + head->next = second; + + second->data = 2; + second->next = NULL; + + printf("Linked list: %d -> %d", head->data, second->data); + return 0; +} diff --git a/C/Easy/3.c b/C/Easy/3.c new file mode 100644 index 00000000..ce5db23e --- /dev/null +++ b/C/Easy/3.c @@ -0,0 +1,14 @@ +#include + +int main() { + int num = 2; + switch (num) { + case 1: + printf("One"); + case 2: + printf("Two"); + case 3: + printf("Three"); + } + return 0; +} \ No newline at end of file diff --git a/C/Easy/30.c b/C/Easy/30.c new file mode 100644 index 00000000..b4fbfcda --- /dev/null +++ b/C/Easy/30.c @@ -0,0 +1,26 @@ +#include + +int main() { + char grade; + printf("Enter your grade (A, B, C, D, or F): "); + scanf(" %c", &grade); + + switch(grade) { + case 'A': + printf("Excellent!"); + break; + case 'B': + printf("Good job!"); + break; + case 'C': + printf("Average performance."); + break; + case 'D': + printf("Need improvement."); + break; + case 'F': + printf("Failed."); + break; + } + return 0; +} diff --git a/C/Easy/31.c b/C/Easy/31.c new file mode 100644 index 00000000..076d2a74 --- /dev/null +++ b/C/Easy/31.c @@ -0,0 +1,9 @@ +#include + +int main() + char str[] ="Google developer student clubs"; + printf("%s\n", str); + return 0; +} + + diff --git a/C/Easy/32.c b/C/Easy/32.c new file mode 100644 index 00000000..1ff3d871 --- /dev/null +++ b/C/Easy/32.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Google developer student clubs!\n") + return 0; +} diff --git a/C/Easy/33.c b/C/Easy/33.c new file mode 100644 index 00000000..df964897 --- /dev/null +++ b/C/Easy/33.c @@ -0,0 +1,8 @@ +#include + +int main() { + for (int i = 1; i <= 5; i+) + printf("%d ", i); + return 0; +} + diff --git a/C/Easy/34.c b/C/Easy/34.c new file mode 100644 index 00000000..76a15e69 --- /dev/null +++ b/C/Easy/34.c @@ -0,0 +1,14 @@ +#include + +____ main() { + + int ______ = {10, 20, 30, 40}; + numbers[4] = 100; + + for (int i = 0; i < 5; i++) { + printf("%d ", numbers[i]); + } + printf("\n"); + + +} diff --git a/C/Easy/35.c b/C/Easy/35.c new file mode 100644 index 00000000..42d1c211 --- /dev/null +++ b/C/Easy/35.c @@ -0,0 +1,26 @@ +#include + +int main() { + + int array1[] = {1, 2, 3}; + int array2[] = {4, 5, 6}; + int concatenated[6]; + + + for (int i = 0; i < __; i++) { + _______ = array1[i]; + } + + + for (int i = 0; i < 3; i++) { + concatenated[____] = array2[i]; + } + + + for (int i = 0; i < __; i++) { + printf("%d ", concatenated[i]); + } + printf("\n"); + + return 0; +} diff --git a/C/Easy/36.c b/C/Easy/36.c new file mode 100644 index 00000000..8024d861 --- /dev/null +++ b/C/Easy/36.c @@ -0,0 +1,12 @@ +#include + + +int multiply(___, ___) { + return a * b; +} + +int main() { + int ____= multiply(5, 3); + printf("%d\n", result); + return 0; +} \ No newline at end of file diff --git a/C/Easy/37.c b/C/Easy/37.c new file mode 100644 index 00000000..a601286a --- /dev/null +++ b/C/Easy/37.c @@ -0,0 +1,14 @@ +#include + +int main() { + + for (int i = 0; i < _; i++) { + printf("%d\n", i); + + + if (i __ 5) { + printf("Reached 5!\n"); + } + } + return 0; +} \ No newline at end of file diff --git a/C/Easy/38.c b/C/Easy/38.c new file mode 100644 index 00000000..e69de29b diff --git a/C/Easy/39.c b/C/Easy/39.c new file mode 100644 index 00000000..f11ae91b --- /dev/null +++ b/C/Easy/39.c @@ -0,0 +1,6 @@ +#include +void main(){ +int x = 5; +float y = (float)x / 2; +printf("y = %d\n", y); +} diff --git a/C/Easy/4.c b/C/Easy/4.c new file mode 100644 index 00000000..80609209 --- /dev/null +++ b/C/Easy/4.c @@ -0,0 +1,6 @@ +#include +int main() { + int arr[5] = {1, 2, 3, 4}; + printf("The first element of the array is %d", arr[5]); + return 0; +} \ No newline at end of file diff --git a/C/Easy/40.c b/C/Easy/40.c new file mode 100644 index 00000000..b9ae2288 --- /dev/null +++ b/C/Easy/40.c @@ -0,0 +1,18 @@ +#include + +int main() { + int i = 0; + +label: + if (i < 10) { + if (i__5) { + i++; + goto label; + } + printf("%d\n", i); + i++; + ___ label; + } + + return 0; +} diff --git a/C/Easy/41.c b/C/Easy/41.c new file mode 100644 index 00000000..2bb31691 --- /dev/null +++ b/C/Easy/41.c @@ -0,0 +1,13 @@ +#include + +int main() { +int x = 5; +if (x < 10) { +printf("x is less than 10\n"); +} +else( x > 10 ){ +printf("x is greater than 10\n"); +} + +return 0; +} \ No newline at end of file diff --git a/C/Easy/42.c b/C/Easy/42.c new file mode 100644 index 00000000..8e4991e7 --- /dev/null +++ b/C/Easy/42.c @@ -0,0 +1,10 @@ +#include +Int main(){ +for (int i = 0; i < 10; i++) { + if (i == 5) { + continue; + } + +} +return 0; +} diff --git a/C/Easy/43.c b/C/Easy/43.c new file mode 100644 index 00000000..052be5a0 --- /dev/null +++ b/C/Easy/43.c @@ -0,0 +1,13 @@ +#include + +union MyUnion { + int x; + char c; +}; + +int main() { + union MyUnion myUnion; + myUnion.x = 10; + myUnion.c = 'A'; + return 0; +} diff --git a/C/Easy/44.c b/C/Easy/44.c new file mode 100644 index 00000000..9d6058ba --- /dev/null +++ b/C/Easy/44.c @@ -0,0 +1,22 @@ +#include + +struct MyStruct { + int x; + char c; +}; + +int main() { + MyStruct myStruct; + myStruct.x = 10; + myStruct.c = 'A'; + + + MyStruct *ptr = __myStruct; + + printf("x: %d\n", myStruct.x); + printf("c: %c\n", myStruct.c); + + printf("Using pointer: x: %d, c: %c\n", ____, ____); + + return 0; +} diff --git a/C/Easy/45.c b/C/Easy/45.c new file mode 100644 index 00000000..cfc47aae --- /dev/null +++ b/C/Easy/45.c @@ -0,0 +1,8 @@ +#include + +int main() { + const int x = 5; + x = 10; + printf("%d\n", x); + return 0; +} diff --git a/C/Easy/46.c b/C/Easy/46.c new file mode 100644 index 00000000..ff0e159d --- /dev/null +++ b/C/Easy/46.c @@ -0,0 +1,12 @@ +#include + +int add_numbers(int a, int b) +int result = a + b; +int main() { +int num1 = 5; +int num2 = 10; + +printf("%d\n", add_numbers(num1, num2)); +return 0; +} + diff --git a/C/Easy/47.c b/C/Easy/47.c new file mode 100644 index 00000000..cae17c47 --- /dev/null +++ b/C/Easy/47.c @@ -0,0 +1,10 @@ +#include + +void my_function(int x, int y) { + printf("%d\n", x + y); +} + +int main() { + my_function(x = 5, 3); + return 0; +} \ No newline at end of file diff --git a/C/Easy/48.c b/C/Easy/48.c new file mode 100644 index 00000000..c48fd359 --- /dev/null +++ b/C/Easy/48.c @@ -0,0 +1,14 @@ +#include + +int infinite_recursion(int n) { + if (n > 10) { + return n; // Base case + } + return infinite_recursion(n + 1); // Recursive call with increment +} + +int main() { + int result = infinite_recursion(0); + printf("%d\n", result); // Print the result + return 0; +} diff --git a/C/Easy/49.c b/C/Easy/49.c new file mode 100644 index 00000000..ba29f7ab --- /dev/null +++ b/C/Easy/49.c @@ -0,0 +1,14 @@ +#include + +void print_elements(int _____, int size) { + for (int i = 0; i _ size; i++) { + printf("%d\n", elements[i]); + } +} + +int main() { + int elements[] = {1, 2, 3}; + int size = ____(elements) / ____(elements[0]); + print_elements(_____, size); + return 0; +} \ No newline at end of file diff --git a/C/Easy/5.c b/C/Easy/5.c new file mode 100644 index 00000000..a74d9726 --- /dev/null +++ b/C/Easy/5.c @@ -0,0 +1,7 @@ +#include + +int main() { + int a = 10; + printf("Value of a: %f\n", a); + return 0; +} \ No newline at end of file diff --git a/C/Easy/50.c b/C/Easy/50.c new file mode 100644 index 00000000..bb637e75 --- /dev/null +++ b/C/Easy/50.c @@ -0,0 +1,10 @@ + +#include +int add(int a, int b) { + +} +int main() { + printf("%d\n", add(5, 10)); + return 0; +} + diff --git a/C/Easy/51.c b/C/Easy/51.c new file mode 100644 index 00000000..5556a056 --- /dev/null +++ b/C/Easy/51.c @@ -0,0 +1,8 @@ +18 +#include +int main() { + printf("Hello, World!\n"; + return 0; +} + +Error: Missing closing parenthesis in printf. \ No newline at end of file diff --git a/C/Easy/52.c b/C/Easy/52.c new file mode 100644 index 00000000..8eae7301 --- /dev/null +++ b/C/Easy/52.c @@ -0,0 +1,7 @@ + +#include +int main() { + int a; + printf("%d\n", a); + return 0; +} diff --git a/C/Easy/53.c b/C/Easy/53.c new file mode 100644 index 00000000..728c845c --- /dev/null +++ b/C/Easy/53.c @@ -0,0 +1,10 @@ + +#include +void func(int a) { + printf("Value: %d\n", a); +} +int main() { + void (*ptr)() = func; + ptr(5); + return 0; +} diff --git a/C/Easy/54.c b/C/Easy/54.c new file mode 100644 index 00000000..f1421390 --- /dev/null +++ b/C/Easy/54.c @@ -0,0 +1,7 @@ + +#include +int main() { + int a = 5; + printf("Value: %f\n", a); + return 0; +} \ No newline at end of file diff --git a/C/Easy/55.c b/C/Easy/55.c new file mode 100644 index 00000000..11b065ca --- /dev/null +++ b/C/Easy/55.c @@ -0,0 +1,8 @@ + +#include +int main() { + int arr[5] = {1, 2, 3, 4, 5}; + printf("%d\n", arr[5]); + return 0; +} + diff --git a/C/Easy/56.c b/C/Easy/56.c new file mode 100644 index 00000000..f4fa8c38 --- /dev/null +++ b/C/Easy/56.c @@ -0,0 +1,9 @@ + +#include +int main() { + int i = 0; + while (i < 5) { + printf("%d\n", i); + } + return 0; +} diff --git a/C/Easy/6.c b/C/Easy/6.c new file mode 100644 index 00000000..f4d6a14d --- /dev/null +++ b/C/Easy/6.c @@ -0,0 +1,9 @@ +#include +int main() { + int x = 10; + while (x >= 0) { + printf("%d\n", x); + x++; + } + return 0; +} diff --git a/C/Easy/7.c b/C/Easy/7.c new file mode 100644 index 00000000..e2c12b29 --- /dev/null +++ b/C/Easy/7.c @@ -0,0 +1,8 @@ +#include + +int main() { + int *ptr; + ptr = 10; + printf("The value of ptr is %d", ptr); + return 0; +} \ No newline at end of file diff --git a/C/Easy/8.c b/C/Easy/8.c new file mode 100644 index 00000000..180c565a --- /dev/null +++ b/C/Easy/8.c @@ -0,0 +1,14 @@ +#include + +struct person { + int age; + float height; +}; + +int main() { + struct peron p1; + p1.age = 25; + p1.height = 5.9; + printf("Age: %d, Height: %.1f", p1.age, p1.height); + return 0; +} \ No newline at end of file diff --git a/C/Easy/9.c b/C/Easy/9.c new file mode 100644 index 00000000..ca3c624c --- /dev/null +++ b/C/Easy/9.c @@ -0,0 +1,11 @@ +#include + +int main() { + int arr[] = {1, 2, 3, 4, 5}; + int sum = 0; + for (int i = 0; i <= 5; i++) { + sum += arr[i]; + } + printf("Sum of array elements: %d\n", sum); + return 0; +} diff --git a/C/Easy/temp.txt b/C/Hard/.gitkeep similarity index 100% rename from C/Easy/temp.txt rename to C/Hard/.gitkeep diff --git a/C/Hard/temp.txt b/C/Hard/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/C/Hard/temp.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/C/Medium/1.c b/C/Medium/1.c new file mode 100644 index 00000000..069bad28 --- /dev/null +++ b/C/Medium/1.c @@ -0,0 +1,24 @@ +#include + +#define SIZE 5 + +int queue[SIZE], front = -1, rear = -1; + +void enqueue(int); +void display(); + +int main() { + enqueue(10); + enqueue(20); + enqueue(30); + display(); + return 0; +} + +void enqueue(int val) { + +} + +void display() { + +} \ No newline at end of file diff --git a/C/Medium/10.c b/C/Medium/10.c new file mode 100644 index 00000000..b3037cc0 --- /dev/null +++ b/C/Medium/10.c @@ -0,0 +1,26 @@ + +// Expected Pattern : +// * * * * * +// * * * * +// * * * +// * * * * +// * * * * * + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == 1 || i == n || j == 1 || j == n || i == j || i + j == n + 1) { + printf("*"); + } else { + printf(" "); + } + } + printf("\n"); + } + + return 0; +} diff --git a/C/Medium/11.c b/C/Medium/11.c new file mode 100644 index 00000000..930c37f2 --- /dev/null +++ b/C/Medium/11.c @@ -0,0 +1,29 @@ +// 18) Pascal's Triangle (Fill in the Blank) +// Expected Pattern: + // 1 + // 1 1 + // 1 2 1 + // 1 3 3 1 + // 1 4 6 4 1 + +#include + +int main() { + int n = 5, coef = 1; + + for (int i = 0; i < n; i++) { + for (int space = 1; space <= n - i; space++) + printf(" "); + + for (int j = 0; j <= i; j++) { + if (j == 0 || i == 0) + coef = 1; + else + coef = coef * (i - j + 1) / ___; // Fill in the blank (___) + printf("%d ", coef); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/12.c b/C/Medium/12.c new file mode 100644 index 00000000..3f974589 --- /dev/null +++ b/C/Medium/12.c @@ -0,0 +1,27 @@ +// 19) Hollow Pyramid Pattern (Fill in the Blank) +// * +// * * +// * * +// * * +// ********* + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n - i; j++) + printf(" "); + + for (int k = 1; k <= 2 * i - 1; k++) { + if (i == ___ || k == 1 || k == ___) // Fill in the blanks (___) + printf("*"); + else + printf(" "); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/13.c b/C/Medium/13.c new file mode 100644 index 00000000..b1cf9943 --- /dev/null +++ b/C/Medium/13.c @@ -0,0 +1,25 @@ +// 20) Hollow Square with Diagonals (Fill in the Blank) +// Expected Pattern: +// * * * * * +// * * * * +// * * * +// * * * * +// * * * * * + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == 1 || i == n || ___ || ___ || i == j || ___ == n + 1) // Fill in the blanks (___) + printf("* "); + else + printf(" "); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/14.c b/C/Medium/14.c new file mode 100644 index 00000000..79e49261 --- /dev/null +++ b/C/Medium/14.c @@ -0,0 +1,20 @@ +// 21) Pointer Arithmetic (Fill in the Blank) + +#include + +int main() { + int arr[5] = {10, 20, 30, 40, 50}; + int *ptr = arr; // Pointer to the first element + + printf("Initial value: %d\n", *ptr); + + // Increment pointer + ptr = ___; // Fill in the blank + printf("After incrementing pointer: %d\n", *ptr); + + // Decrement pointer + ptr = ___; // Fill in the blank + printf("After decrementing pointer: %d\n", *ptr); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/15.c b/C/Medium/15.c new file mode 100644 index 00000000..ab7659f2 --- /dev/null +++ b/C/Medium/15.c @@ -0,0 +1,19 @@ +// Expected Answer: Result of addition: 30 + +#include +int add(int a, int b) { + return a + b; +} + +int main { + int (*func_ptr)(int, int); + + func_ptr = ___; // Fill in the blank + + // Call the function using the pointer + int result = func_ptr(10, 20); + + printf("Result of addition: %d\n", result); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/16.c b/C/Medium/16.c new file mode 100644 index 00000000..adbdf1a6 --- /dev/null +++ b/C/Medium/16.c @@ -0,0 +1,36 @@ +// 23) Memory Allocation Using malloc (Fill in the Blank) + +#include +#include +int main() { + int *arr; + int n; + + printf("Enter the number of elements: "); + scanf("%d", &n); + + // Allocate memory for n elements + arr = (int*) ___; // Fill in the blank + + if (arr == NULL) { + printf("Memory allocation failed!\n"); + return 1; + } + + + for (int i = 0; i < n; i++) { + arr[i] = i + 1; + } + + + for (int i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + + printf("\n"); + + // Free the allocated memory + ___; // Fill in the blank + + return 0; +} \ No newline at end of file diff --git a/C/Medium/17.c b/C/Medium/17.c new file mode 100644 index 00000000..db04fe71 --- /dev/null +++ b/C/Medium/17.c @@ -0,0 +1,24 @@ +// 24) Fibonacci Series Using Recursion (Fill in the Blank) +#include + +// Function to calculate Fibonacci +int fibonacci(int n) { + if (n == 0) + return ___; // Fill in the blank + else if (n == 1) + return ___; // Fill in the blank + else + return fibonacci(n - 1) + fibonacci(___); // Fill in the blank +} +int main() { + int n; + + printf("Enter the number of terms: "); + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + printf("%d ", fibonacci(i)); + } + + return 0; +} diff --git a/C/Medium/18.c b/C/Medium/18.c new file mode 100644 index 00000000..e47ec0cd --- /dev/null +++ b/C/Medium/18.c @@ -0,0 +1,21 @@ +// 25) Fibonacci Series Using Iteration (Fill in the Blank) + +#include + +int main() { + int n, t1 = 0, t2 = 1, nextTerm; + + printf("Enter the number of terms: "); + scanf("%d", &n); + + printf("Fibonacci Series: %d %d ", t1, t2); + + for (int i = 3; i <= n; i++) { + nextTerm = ___ + ___; // Fill in the blank + printf("%d ", nextTerm); + t1 = ___; // Fill in the blank + t2 = ___; // Fill in the blank + } + + return 0; +} diff --git a/C/Medium/19.c b/C/Medium/19.c new file mode 100644 index 00000000..8455a469 --- /dev/null +++ b/C/Medium/19.c @@ -0,0 +1,21 @@ + +// Expected Answer : +// Primary diagonal sum: 15 +// Secondary diagonal sum: 15 + +#include + +int main() { + int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + int primary_sum = 0, secondary_sum = 0; + + for (int i = 0; i < 3; i++) { + primary_sum += matrix[i][i]; + secondary_sum += matrix[i][3-i]; + } + + printf("Primary diagonal sum: %d\n", primary_sum); + printf("Secondary diagonal sum: %d\n", secondary_sum); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/2.c b/C/Medium/2.c new file mode 100644 index 00000000..1e2f5695 --- /dev/null +++ b/C/Medium/2.c @@ -0,0 +1,14 @@ +7) Reverse the numbers + +#include +int main() { + int num = 12345; + int reversed = 0; + while (num == 0) { + int digit = num % 10; + reversed = reversed * 10 - digit; + num /= 10; + } + printf("Reversed number: %d\n", reversed); + return 0; +} \ No newline at end of file diff --git a/C/Medium/20.c b/C/Medium/20.c new file mode 100644 index 00000000..6e47f60c --- /dev/null +++ b/C/Medium/20.c @@ -0,0 +1,19 @@ +27) Finding Maximum in an Array Using Pointers +Expected Answer : Maximum value: 50 + +#include + +int main() { + int arr[5] = {10, 20, 30, 40, 50}; + int *ptr = arr; + int max = *ptr; + + for (int i = 0; i < 5; i++) { + if (*(ptr + i) > max) + max = ptr + i; + } + + printf("Maximum value: %d\n", max); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/21.c b/C/Medium/21.c new file mode 100644 index 00000000..ad7a7427 --- /dev/null +++ b/C/Medium/21.c @@ -0,0 +1,24 @@ +// 30) Prime Number Check Using a While Loop + + +#include + +int isPrime(int n) { + int i = 2; + while (i < n / 2) { + if (n % i == 0) + return 0; + i++; + } + return 1; +} + +int main() { + int num = 29; + if (isPrime(num)) + printf("%d is prime\n", num); + else + printf("%d is not prime\n", num); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/22.c b/C/Medium/22.c new file mode 100644 index 00000000..f7cf3bff --- /dev/null +++ b/C/Medium/22.c @@ -0,0 +1,6 @@ +#include +int main() { + int 1stNum = 5; + printf("%d", 1stNum); + return 0; +} diff --git a/C/Medium/23.c b/C/Medium/23.c new file mode 100644 index 00000000..abc917e0 --- /dev/null +++ b/C/Medium/23.c @@ -0,0 +1,10 @@ +#include +int main() { + int x = 1; + switch(x) { + case 1 + printf("One"); + break; + } + return 0; +} diff --git a/C/Medium/24.c b/C/Medium/24.c new file mode 100644 index 00000000..d3b50347 --- /dev/null +++ b/C/Medium/24.c @@ -0,0 +1,6 @@ +#include +int main() { + int arr[5]; + printf("%d", arr[5]); + return 0; +} diff --git a/C/Medium/25.c b/C/Medium/25.c new file mode 100644 index 00000000..f13283e3 --- /dev/null +++ b/C/Medium/25.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello" + "World"); + return 0; +} diff --git a/C/Medium/26.c b/C/Medium/26.c new file mode 100644 index 00000000..b8ec18b7 --- /dev/null +++ b/C/Medium/26.c @@ -0,0 +1,7 @@ +#include +int main() { + for (; i < 10; i++) { + printf("%d", i); + } + return 0; +} diff --git a/C/Medium/27.c b/C/Medium/27.c new file mode 100644 index 00000000..409e429e --- /dev/null +++ b/C/Medium/27.c @@ -0,0 +1,9 @@ +#include +int main() { + if (1) { + printf("True"); + } + printf("False"); + return 0; +} +  diff --git a/C/Medium/28.c b/C/Medium/28.c new file mode 100644 index 00000000..443073b5 --- /dev/null +++ b/C/Medium/28.c @@ -0,0 +1,6 @@ +#include +int main() { + int *p; + printf("%d", *p); + return 0; +} diff --git a/C/Medium/29.c b/C/Medium/29.c new file mode 100644 index 00000000..1c5f640a --- /dev/null +++ b/C/Medium/29.c @@ -0,0 +1,8 @@ +#include +struct { + int x; +} myStruct; +int main() { + printf("%d", myStruct.x); + return 0; +} diff --git a/C/Medium/3.c b/C/Medium/3.c new file mode 100644 index 00000000..7ca92f4d --- /dev/null +++ b/C/Medium/3.c @@ -0,0 +1,12 @@ + + +#include + +int main() { + int i = 0; + while (i < 10) { + printf("%d\n", i); + i--; + } + return 0; +} \ No newline at end of file diff --git a/C/Medium/30.c b/C/Medium/30.c new file mode 100644 index 00000000..e0c4d7c7 --- /dev/null +++ b/C/Medium/30.c @@ -0,0 +1,13 @@ +// Complete the code to print size of array + +#include + +void printArray(int arr[]) { + printf("%d", sizeof(arr)); +} + +int main() { + int arr[5]; + printArray(arr); + return 0; +} diff --git a/C/Medium/31.c b/C/Medium/31.c new file mode 100644 index 00000000..9cfdc580 --- /dev/null +++ b/C/Medium/31.c @@ -0,0 +1,21 @@ +// Complete the code to find a duplicate number in an array of size n where each number appears exactly twice except for one number which appears once. + +#include +int main() { + int arr[] = {1, 2, 3, 4, 2}; + int n = sizeof(arr) / sizeof(arr[0]); + int max = n; + int count[max + 1]; + + for (int i = 0; i <= max; i++) { + count[i] = 0; + } + for (int i = 0; i < n; i++) { + if (count[arr[i]] == 2) { + printf("The duplicate number is %d\n", arr[i]); + break; + } + count[arr[i]]++; + } + return 0; +} diff --git a/C/Medium/32.c b/C/Medium/32.c new file mode 100644 index 00000000..194ad737 --- /dev/null +++ b/C/Medium/32.c @@ -0,0 +1,30 @@ +// Complete the code to reverse the array + +#include + +void reverseArray(int arr[], int n) { + int start = 0, end = n - 1; + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + + start++; + end--; + } + +int main() { + int arr[] = {1, 2, 3, 4, 5, 6}; + int n = sizeof(arr) / sizeof(arr[0]); + + reverseArray(arr, n); + + printf("Reversed array: "); + for (int i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + return 0; +} + diff --git a/C/Medium/33.c b/C/Medium/33.c new file mode 100644 index 00000000..6c5ad955 --- /dev/null +++ b/C/Medium/33.c @@ -0,0 +1,21 @@ +// Complete the code to print the following pattern +// 1 +// 1 2 +// 1 2 3 +// 1 2 3 4 +// 1 2 3 4 5 + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + printf("%d ", j); + } + printf("\n"); + } + + return 0; +} diff --git a/C/Medium/34.c b/C/Medium/34.c new file mode 100644 index 00000000..29d51092 --- /dev/null +++ b/C/Medium/34.c @@ -0,0 +1,17 @@ +// Complete the code to calculate the sum of elements in the array. + +#include + +int main() { + int arr[] = {1, 2, 3, 4, 5}; + int sum = ; + int n = 5; + + for (int i = ) { // Fill in the blank to complete the for loop + sum arr[i]; + } + + printf("Sum of array elements: %d\n", sum); + + return 0; +} diff --git a/C/Medium/35.c b/C/Medium/35.c new file mode 100644 index 00000000..96ade585 --- /dev/null +++ b/C/Medium/35.c @@ -0,0 +1,27 @@ +// Complete the code to find the second smallest element in an array of integers. + +#include + +int main() { + int arr[] = {12, 13, 1, 10, 34, 16}; + int n = sizeof(arr) / sizeof(arr[0]); + int first, second; + + first = second = -1; + + for (int i = 0; i < n; i++) { + if (arr[i] < first) { + second = first; + first = arr[i]; + } else if (arr[i] < second && arr[i] != first) { + second = arr[i]; + } + } + + if (second == -1) + printf("No second smallest element.\n"); + else + printf("The second smallest element is %d\n", second); + + return 0; +} diff --git a/C/Medium/36.c b/C/Medium/36.c new file mode 100644 index 00000000..a2c01280 --- /dev/null +++ b/C/Medium/36.c @@ -0,0 +1,28 @@ +// Complete the code to implement Binary Search. + +#include + +int binarySearch(int arr[], int low, int high, int x) +{ + while (low <= high) { + int mid = (low + high)/ 2; + if (arr[high] == x) + return mid; + if (arr[mid] < x) + high = mid + 1; + else + low = mid - 1; + } + return -1; +} + +int main(void) +{ + int arr[] = { 3,7,9,23,45,67,89,456,789}; + int n = sizeof(arr)/sizeof(arr[0]); + int x = 67; + int result = binarySearch(arr, 0,n - 1,x); + if(result==-1) printf("Element is not present in array"); + else printf("Element is present at index %d",result); + +} diff --git a/C/Medium/37.c b/C/Medium/37.c new file mode 100644 index 00000000..fdbf5e43 --- /dev/null +++ b/C/Medium/37.c @@ -0,0 +1,17 @@ +// Complete the code to gnerate a multiplication table + +#include +void print_table(int multiplier, int num){ + int product; + } +int main(){ +int num , multiplier; + printf("Enter the Range of Multiplication table: "); + scanf("%d",&multiplier); + printf("Enter the num. to generate the table of: "); + scanf("%d", &num); + + print_table(multiplier, num); + + return 0; +} diff --git a/C/Medium/38.c b/C/Medium/38.c new file mode 100644 index 00000000..87046d05 --- /dev/null +++ b/C/Medium/38.c @@ -0,0 +1,25 @@ +// Complete the code to check whether number is prime or not + +#include +#include + +___ isPrime(int num) { + if (num>=1) return false; + for (int i = 2; i < __; i++){ + if (num %i== 0) return __; + } + return ___; +} + +int main() { + int number = 29; + + if (isPrime(number)) { + printf("%d is a prime number.\n",number); + } else { + printf("%d is not a prime number.\n",number); + } + + return 0; +} + diff --git a/C/Medium/39.c b/C/Medium/39.c new file mode 100644 index 00000000..ca1da765 --- /dev/null +++ b/C/Medium/39.c @@ -0,0 +1,21 @@ +// Complete the code to compare string value to enter a password + +#include +#include + +int main() { + char default = "Invalid TRY AGAIN!"; + char password = "password"; + char entered_pass[50]; + + printf("Enter password: "); + scanf("%c", entered_pass); + if (___(entered_pass, password) == 0) { + printf("Logged in!\n"); + } + else { + printf("%s\n", default); + } + + return 0; +} diff --git a/C/Medium/4.c b/C/Medium/4.c new file mode 100644 index 00000000..2a4f6a05 --- /dev/null +++ b/C/Medium/4.c @@ -0,0 +1,14 @@ +10) Dynamic Memory Allocation + +#include +#include + +int main() { + int *arr; + arr = malloc(5 * sizeof(int)); + for (int i = 0; i <= 5; i++) { // Error: out of bounds access + arr[i] = i; + } + free(arr); + return 0; +} \ No newline at end of file diff --git a/C/Medium/40.c b/C/Medium/40.c new file mode 100644 index 00000000..6aa48720 --- /dev/null +++ b/C/Medium/40.c @@ -0,0 +1,13 @@ +#include + +int main() { +int matrix[3][2] = {{21, 65}, {25, 56}, {54, 22}}; + +for (int i = 0; i < 4; i++) { +for (int j = 0; j < 4; j++) { +printf("%d ", matrix[i][j]); +} +} + +return 0; +} \ No newline at end of file diff --git a/C/Medium/41.c b/C/Medium/41.c new file mode 100644 index 00000000..3d8e7244 --- /dev/null +++ b/C/Medium/41.c @@ -0,0 +1,25 @@ +int main() { + int arr[] = {1, 2, 3, 4, 5, 6}; + int size = ___(arr) / ___(arr[0]); + + printf("Original array:\n"); + for (int i = 0; i <___; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + + for (int i = 0; i <___; i++) { + if (arr[i] % 2 ___ 0) { + arr[i] *= 2; + } + } + + printf("Modified array:\n"); + for (int i = 0; i < size; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/42.c b/C/Medium/42.c new file mode 100644 index 00000000..84252475 --- /dev/null +++ b/C/Medium/42.c @@ -0,0 +1,11 @@ +#include +int main(){ +int x = 5; +switch (x) { + case 5: + printf("x = 5"); + case 6: + printf("x = 6"); + break; +} +} diff --git a/C/Medium/43.c b/C/Medium/43.c new file mode 100644 index 00000000..a0144a4d --- /dev/null +++ b/C/Medium/43.c @@ -0,0 +1,10 @@ +#include + +enum Color { RED, GREEN, BLUE }; + +int main() { + Color myColor = "RED"; + printf("Color value: %d\n", myColor); // Outputs 0 for RED + + return 0; +} diff --git a/C/Medium/44.c b/C/Medium/44.c new file mode 100644 index 00000000..7ab4d8b0 --- /dev/null +++ b/C/Medium/44.c @@ -0,0 +1,9 @@ +#include + +int main() { + int num = 10; + char letter = 'A'; + num = letter; + printf("Num: %d\n", num); + return 0; +} diff --git a/C/Medium/45.c b/C/Medium/45.c new file mode 100644 index 00000000..dec0e27d --- /dev/null +++ b/C/Medium/45.c @@ -0,0 +1,7 @@ + +#include +int main() { + int *ptr; + printf("%d\n", *ptr); + return 0; +} diff --git a/C/Medium/46.c b/C/Medium/46.c new file mode 100644 index 00000000..bc0b9555 --- /dev/null +++ b/C/Medium/46.c @@ -0,0 +1,10 @@ + +#include +#include +int main() { + int *arr = malloc(5 * sizeof(int)); + arr[5] = 10; + printf("%d\n", arr[5]); + free(arr); + return 0; +} diff --git a/C/Medium/47.c b/C/Medium/47.c new file mode 100644 index 00000000..689a14a7 --- /dev/null +++ b/C/Medium/47.c @@ -0,0 +1,18 @@ +22 +#include +#include +struct Node { + int data; + struct Node *next; +}; +void insert(struct Node **head, int value) { + struct Node *newNode = malloc(sizeof(struct Node)); + newNode->data = value; + newNode->next = *head; + *head = newNode; +} +int main() { + struct Node *head = NULL; + insert(&head, 10); + return 0; +} \ No newline at end of file diff --git a/C/Medium/48.c b/C/Medium/48.c new file mode 100644 index 00000000..e0100d09 --- /dev/null +++ b/C/Medium/48.c @@ -0,0 +1,10 @@ + +#include +void recurse() { + printf("Recursing...\n"); + recurse(); +} +int main() { + recurse(); + return 0; +} diff --git a/C/Medium/49.c b/C/Medium/49.c new file mode 100644 index 00000000..c884e312 --- /dev/null +++ b/C/Medium/49.c @@ -0,0 +1,15 @@ + +#include +int main() { + int a = 2; + switch (a) { + case 1: + printf("One\n"); + case 2: + printf("Two\n"); + case 3: + printf("Three\n"); + break; + } + return 0; +} \ No newline at end of file diff --git a/C/Medium/5.c b/C/Medium/5.c new file mode 100644 index 00000000..f55a11f1 --- /dev/null +++ b/C/Medium/5.c @@ -0,0 +1,13 @@ +11) Recursive Function + +#include + +int factorial(int n) { + if (n == 0) return 1; + return n * factorial(n); +} + +int main() { + printf("Factorial: %d\n", factorial(5)); + return 0; +} diff --git a/C/Medium/50.c b/C/Medium/50.c new file mode 100644 index 00000000..375e03f9 --- /dev/null +++ b/C/Medium/50.c @@ -0,0 +1,8 @@ + +#include +int main() { + int arr[5] = {1, 2, 3, 4, 5}; + int *ptr = arr; + printf("%d\n", *(ptr + 5)); + return 0; +} diff --git a/C/Medium/51.c b/C/Medium/51.c new file mode 100644 index 00000000..b4eff896 --- /dev/null +++ b/C/Medium/51.c @@ -0,0 +1,10 @@ + +#include +void myFunction(int a); +int main() { + myFunction(5.5); + return 0; +} +void myFunction(int a) { + printf("%d\n", a); +} diff --git a/C/Medium/52.c b/C/Medium/52.c new file mode 100644 index 00000000..678bd6fe --- /dev/null +++ b/C/Medium/52.c @@ -0,0 +1,7 @@ + +#include +int main() { + int *ptr = (int *)malloc(sizeof(int)); + // Missing free(ptr); + return 0; +} \ No newline at end of file diff --git a/C/Medium/6.c b/C/Medium/6.c new file mode 100644 index 00000000..cbeecd88 --- /dev/null +++ b/C/Medium/6.c @@ -0,0 +1,13 @@ + + +#include + +int sum(int a, int b, int c) { + return a + b; +} + +int main() { + int result = sum(3, 4, 5); + printf("Sum: %d\n", result); + return 0; +} \ No newline at end of file diff --git a/C/Medium/7.c b/C/Medium/7.c new file mode 100644 index 00000000..2cf67a94 --- /dev/null +++ b/C/Medium/7.c @@ -0,0 +1,21 @@ + +// Expected Pattern +// 1 +// 1 2 +// 1 2 3 +// 1 2 3 4 +// 1 2 3 4 5 + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + printf("%d ", j); + } + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/8.c b/C/Medium/8.c new file mode 100644 index 00000000..1115ca12 --- /dev/null +++ b/C/Medium/8.c @@ -0,0 +1,26 @@ + +// Expected Pattern : +// * +// *** +// ***** +// ******* +// ********* + + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + for (int k = 1; k <= i; k++) { + printf("*"); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/9.c b/C/Medium/9.c new file mode 100644 index 00000000..4bf3224a --- /dev/null +++ b/C/Medium/9.c @@ -0,0 +1,36 @@ +// Expected Pattern +// * +// *** +// ***** +// ******* +// ********* +// ******* +// ***** +// *** +// * + +#include + +int main() { + int n = 5; + + // Upper part of the diamond + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n - i; j++) + printf(" "); + for (int k = 1; k < i; k++) + printf("*"); + printf("\n"); + } + + // Lower part of the diamond + for (int i = n - 1; i >= 1; i--) { + for (int j = 1; j <= n - i; j++) + printf(" "); + for (int k = 1; k < i; k++) + printf("*"); + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/temp.txt b/C/Medium/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/C/Medium/temp.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/C/temp.txt b/C/temp.txt deleted file mode 100644 index 5d72a670..00000000 --- a/C/temp.txt +++ /dev/null @@ -1 +0,0 @@ -"." From 4c4f7ee6241060a5aa894428070850a3bae278d2 Mon Sep 17 00:00:00 2001 From: Ariyan-25 <167085284+Ariyan-25@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:12:35 +0530 Subject: [PATCH 31/62] ariyan --- Java/Easy/100.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/100.java b/Java/Easy/100.java index 57792c6e..c1be92f5 100644 --- a/Java/Easy/100.java +++ b/Java/Easy/100.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { String[] names = {"Alice", "Bob"}; - System.out.println(names.get(0)); + System.out.println(names[0]); } } From a12b4b6220bee86b331169e368a881962d1b980b Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 17:47:48 +0000 Subject: [PATCH 32/62] Merged Python --- Python2/Easy/9.py => Python/Easy/100.py | 0 Python2/Easy/1.py => Python/Easy/51.py | 0 Python2/Easy/10.py => Python/Easy/52.py | 0 Python2/Easy/11.py => Python/Easy/53.py | 0 Python2/Easy/12.py => Python/Easy/54.py | 0 Python2/Easy/13.py => Python/Easy/55.py | 0 Python2/Easy/14.py => Python/Easy/56.py | 0 Python2/Easy/15.py => Python/Easy/57.py | 0 Python2/Easy/16.py => Python/Easy/58.py | 0 Python2/Easy/17.py => Python/Easy/59.py | 0 Python2/Easy/18.py => Python/Easy/60.py | 0 Python2/Easy/19.py => Python/Easy/61.py | 0 Python2/Easy/2.py => Python/Easy/62.py | 0 Python2/Easy/20.py => Python/Easy/63.py | 0 Python2/Easy/21.py => Python/Easy/64.py | 0 Python2/Easy/22.py => Python/Easy/65.py | 0 Python2/Easy/23.py => Python/Easy/66.py | 0 Python2/Easy/24.py => Python/Easy/67.py | 0 Python2/Easy/25.py => Python/Easy/68.py | 0 Python2/Easy/26.py => Python/Easy/69.py | 0 Python2/Easy/27.py => Python/Easy/70.py | 0 Python2/Easy/28.py => Python/Easy/71.py | 0 Python2/Easy/29.py => Python/Easy/72.py | 0 Python2/Easy/3.py => Python/Easy/73.py | 0 Python2/Easy/30.py => Python/Easy/74.py | 0 Python2/Easy/31.py => Python/Easy/75.py | 0 Python2/Easy/32.py => Python/Easy/76.py | 0 Python2/Easy/33.py => Python/Easy/77.py | 0 Python2/Easy/34.py => Python/Easy/78.py | 0 Python2/Easy/35.py => Python/Easy/79.py | 0 Python2/Easy/36.py => Python/Easy/80.py | 0 Python2/Easy/37.py => Python/Easy/81.py | 0 Python2/Easy/38.py => Python/Easy/82.py | 0 Python2/Easy/39.py => Python/Easy/83.py | 0 Python2/Easy/4.py => Python/Easy/84.py | 0 Python2/Easy/40.py => Python/Easy/85.py | 0 Python2/Easy/41.py => Python/Easy/86.py | 0 Python2/Easy/42.py => Python/Easy/87.py | 0 Python2/Easy/43.py => Python/Easy/88.py | 0 Python2/Easy/44.py => Python/Easy/89.py | 0 Python2/Easy/45.py => Python/Easy/90.py | 0 Python2/Easy/46.py => Python/Easy/91.py | 0 Python2/Easy/47.py => Python/Easy/92.py | 0 Python2/Easy/48.py => Python/Easy/93.py | 0 Python2/Easy/49.py => Python/Easy/94.py | 0 Python2/Easy/5.py => Python/Easy/95.py | 0 Python2/Easy/50.py => Python/Easy/96.py | 0 Python2/Easy/6.py => Python/Easy/97.py | 0 Python2/Easy/7.py => Python/Easy/98.py | 0 Python2/Easy/8.py => Python/Easy/99.py | 0 Python2/Hard/9.py => Python/Hard/100.py | 0 Python/Hard/51.py | 50 ++++++++------- Python/Hard/52.py | 71 ++++++++++++++++----- Python2/Hard/11.py => Python/Hard/53.py | 0 Python2/Hard/12.py => Python/Hard/54.py | 0 Python2/Hard/13.py => Python/Hard/55.py | 0 Python2/Hard/14.py => Python/Hard/56.py | 0 Python2/Hard/15.py => Python/Hard/57.py | 0 Python2/Hard/16.py => Python/Hard/58.py | 0 Python2/Hard/17.py => Python/Hard/59.py | 0 Python2/Hard/18.py => Python/Hard/60.py | 0 Python2/Hard/19.py => Python/Hard/61.py | 0 Python2/Hard/2.py => Python/Hard/62.py | 0 Python2/Hard/20.py => Python/Hard/63.py | 0 Python2/Hard/21.py => Python/Hard/64.py | 0 Python2/Hard/22.py => Python/Hard/65.py | 0 Python2/Hard/23.py => Python/Hard/66.py | 0 Python2/Hard/24.py => Python/Hard/67.py | 0 Python2/Hard/25.py => Python/Hard/68.py | 0 Python2/Hard/26.py => Python/Hard/69.py | 0 Python2/Hard/27.py => Python/Hard/70.py | 0 Python2/Hard/28.py => Python/Hard/71.py | 0 Python2/Hard/29.py => Python/Hard/72.py | 0 Python2/Hard/3.py => Python/Hard/73.py | 0 Python2/Hard/30.py => Python/Hard/74.py | 0 Python2/Hard/31.py => Python/Hard/75.py | 0 Python2/Hard/32.py => Python/Hard/76.py | 0 Python2/Hard/33.py => Python/Hard/77.py | 0 Python2/Hard/34.py => Python/Hard/78.py | 0 Python2/Hard/35.py => Python/Hard/79.py | 0 Python2/Hard/36.py => Python/Hard/80.py | 0 Python2/Hard/37.py => Python/Hard/81.py | 0 Python2/Hard/38.py => Python/Hard/82.py | 0 Python2/Hard/39.py => Python/Hard/83.py | 0 Python2/Hard/4.py => Python/Hard/84.py | 0 Python2/Hard/40.py => Python/Hard/85.py | 0 Python2/Hard/41.py => Python/Hard/86.py | 0 Python2/Hard/42.py => Python/Hard/87.py | 0 Python2/Hard/43.py => Python/Hard/88.py | 0 Python2/Hard/44.py => Python/Hard/89.py | 0 Python2/Hard/45.py => Python/Hard/90.py | 0 Python2/Hard/46.py => Python/Hard/91.py | 0 Python2/Hard/47.py => Python/Hard/92.py | 0 Python2/Hard/48.py => Python/Hard/93.py | 0 Python2/Hard/49.py => Python/Hard/94.py | 0 Python2/Hard/5.py => Python/Hard/95.py | 0 Python2/Hard/50.py => Python/Hard/96.py | 0 Python2/Hard/6.py => Python/Hard/97.py | 0 Python2/Hard/7.py => Python/Hard/98.py | 0 Python2/Hard/8.py => Python/Hard/99.py | 0 Python2/Medium/9.py => Python/Medium/100.py | 0 Python2/Medium/1.py => Python/Medium/51.py | 0 Python/Medium/52.py | 16 +++-- Python2/Medium/11.py => Python/Medium/53.py | 0 Python2/Medium/12.py => Python/Medium/54.py | 0 Python/Medium/55.py | 16 ++++- Python2/Medium/14.py => Python/Medium/56.py | 0 Python2/Medium/15.py => Python/Medium/57.py | 0 Python2/Medium/16.py => Python/Medium/58.py | 0 Python2/Medium/17.py => Python/Medium/59.py | 0 Python2/Medium/18.py => Python/Medium/60.py | 0 Python/Medium/61.py | 26 ++++---- Python2/Medium/2.py => Python/Medium/62.py | 0 Python2/Medium/20.py => Python/Medium/63.py | 0 Python2/Medium/21.py => Python/Medium/64.py | 0 Python/Medium/65.py | 32 +++------- Python2/Medium/23.py => Python/Medium/66.py | 0 Python2/Medium/24.py => Python/Medium/67.py | 0 Python2/Medium/25.py => Python/Medium/68.py | 0 Python/Medium/69.py | 34 +++------- Python2/Medium/27.py => Python/Medium/70.py | 0 Python2/Medium/28.py => Python/Medium/71.py | 0 Python2/Medium/29.py => Python/Medium/72.py | 0 Python/Medium/73.py | 13 +++- Python2/Medium/30.py => Python/Medium/74.py | 0 Python/Medium/75.py | 12 ++-- Python/Medium/76.py | 28 ++++---- Python2/Medium/33.py => Python/Medium/77.py | 0 Python2/Medium/34.py => Python/Medium/78.py | 0 Python/Medium/79.py | 29 +++------ Python2/Medium/36.py => Python/Medium/80.py | 0 Python/Medium/81.py | 47 +++++++------- Python2/Medium/38.py => Python/Medium/82.py | 0 Python2/Medium/39.py => Python/Medium/83.py | 0 Python2/Medium/4.py => Python/Medium/84.py | 0 Python2/Medium/40.py => Python/Medium/85.py | 0 Python2/Medium/41.py => Python/Medium/86.py | 0 Python2/Medium/42.py => Python/Medium/87.py | 0 Python2/Medium/43.py => Python/Medium/88.py | 0 Python2/Medium/44.py => Python/Medium/89.py | 0 Python2/Medium/45.py => Python/Medium/90.py | 0 Python2/Medium/46.py => Python/Medium/91.py | 0 Python2/Medium/47.py => Python/Medium/92.py | 0 Python/Medium/93.py | 18 +++++- Python2/Medium/49.py => Python/Medium/94.py | 0 Python2/Medium/5.py => Python/Medium/95.py | 0 Python/Medium/96.py | 17 ++--- Python2/Medium/6.py => Python/Medium/97.py | 0 Python/Medium/98.py | 16 +++-- Python/Medium/99.py | 14 +++- Python2/Easy/temp.txt | 1 - Python2/Hard/1.py | 26 -------- Python2/Hard/10.py | 54 ---------------- Python2/Hard/temp.txt | 1 - Python2/Medium/10.py | 9 --- Python2/Medium/13.py | 13 ---- Python2/Medium/19.py | 14 ---- Python2/Medium/22.py | 9 --- Python2/Medium/26.py | 12 ---- Python2/Medium/3.py | 10 --- Python2/Medium/31.py | 8 --- Python2/Medium/32.py | 12 ---- Python2/Medium/35.py | 10 --- Python2/Medium/37.py | 23 ------- Python2/Medium/48.py | 15 ----- Python2/Medium/50.py | 7 -- Python2/Medium/7.py | 11 ---- Python2/Medium/8.py | 12 ---- Python2/Medium/temp.txt | 1 - Python2/temp.txt | 1 - 170 files changed, 242 insertions(+), 446 deletions(-) rename Python2/Easy/9.py => Python/Easy/100.py (100%) rename Python2/Easy/1.py => Python/Easy/51.py (100%) rename Python2/Easy/10.py => Python/Easy/52.py (100%) rename Python2/Easy/11.py => Python/Easy/53.py (100%) rename Python2/Easy/12.py => Python/Easy/54.py (100%) rename Python2/Easy/13.py => Python/Easy/55.py (100%) rename Python2/Easy/14.py => Python/Easy/56.py (100%) rename Python2/Easy/15.py => Python/Easy/57.py (100%) rename Python2/Easy/16.py => Python/Easy/58.py (100%) rename Python2/Easy/17.py => Python/Easy/59.py (100%) rename Python2/Easy/18.py => Python/Easy/60.py (100%) rename Python2/Easy/19.py => Python/Easy/61.py (100%) rename Python2/Easy/2.py => Python/Easy/62.py (100%) rename Python2/Easy/20.py => Python/Easy/63.py (100%) rename Python2/Easy/21.py => Python/Easy/64.py (100%) rename Python2/Easy/22.py => Python/Easy/65.py (100%) rename Python2/Easy/23.py => Python/Easy/66.py (100%) rename Python2/Easy/24.py => Python/Easy/67.py (100%) rename Python2/Easy/25.py => Python/Easy/68.py (100%) rename Python2/Easy/26.py => Python/Easy/69.py (100%) rename Python2/Easy/27.py => Python/Easy/70.py (100%) rename Python2/Easy/28.py => Python/Easy/71.py (100%) rename Python2/Easy/29.py => Python/Easy/72.py (100%) rename Python2/Easy/3.py => Python/Easy/73.py (100%) rename Python2/Easy/30.py => Python/Easy/74.py (100%) rename Python2/Easy/31.py => Python/Easy/75.py (100%) rename Python2/Easy/32.py => Python/Easy/76.py (100%) rename Python2/Easy/33.py => Python/Easy/77.py (100%) rename Python2/Easy/34.py => Python/Easy/78.py (100%) rename Python2/Easy/35.py => Python/Easy/79.py (100%) rename Python2/Easy/36.py => Python/Easy/80.py (100%) rename Python2/Easy/37.py => Python/Easy/81.py (100%) rename Python2/Easy/38.py => Python/Easy/82.py (100%) rename Python2/Easy/39.py => Python/Easy/83.py (100%) rename Python2/Easy/4.py => Python/Easy/84.py (100%) rename Python2/Easy/40.py => Python/Easy/85.py (100%) rename Python2/Easy/41.py => Python/Easy/86.py (100%) rename Python2/Easy/42.py => Python/Easy/87.py (100%) rename Python2/Easy/43.py => Python/Easy/88.py (100%) rename Python2/Easy/44.py => Python/Easy/89.py (100%) rename Python2/Easy/45.py => Python/Easy/90.py (100%) rename Python2/Easy/46.py => Python/Easy/91.py (100%) rename Python2/Easy/47.py => Python/Easy/92.py (100%) rename Python2/Easy/48.py => Python/Easy/93.py (100%) rename Python2/Easy/49.py => Python/Easy/94.py (100%) rename Python2/Easy/5.py => Python/Easy/95.py (100%) rename Python2/Easy/50.py => Python/Easy/96.py (100%) rename Python2/Easy/6.py => Python/Easy/97.py (100%) rename Python2/Easy/7.py => Python/Easy/98.py (100%) rename Python2/Easy/8.py => Python/Easy/99.py (100%) rename Python2/Hard/9.py => Python/Hard/100.py (100%) rename Python2/Hard/11.py => Python/Hard/53.py (100%) rename Python2/Hard/12.py => Python/Hard/54.py (100%) rename Python2/Hard/13.py => Python/Hard/55.py (100%) rename Python2/Hard/14.py => Python/Hard/56.py (100%) rename Python2/Hard/15.py => Python/Hard/57.py (100%) rename Python2/Hard/16.py => Python/Hard/58.py (100%) rename Python2/Hard/17.py => Python/Hard/59.py (100%) rename Python2/Hard/18.py => Python/Hard/60.py (100%) rename Python2/Hard/19.py => Python/Hard/61.py (100%) rename Python2/Hard/2.py => Python/Hard/62.py (100%) rename Python2/Hard/20.py => Python/Hard/63.py (100%) rename Python2/Hard/21.py => Python/Hard/64.py (100%) rename Python2/Hard/22.py => Python/Hard/65.py (100%) rename Python2/Hard/23.py => Python/Hard/66.py (100%) rename Python2/Hard/24.py => Python/Hard/67.py (100%) rename Python2/Hard/25.py => Python/Hard/68.py (100%) rename Python2/Hard/26.py => Python/Hard/69.py (100%) rename Python2/Hard/27.py => Python/Hard/70.py (100%) rename Python2/Hard/28.py => Python/Hard/71.py (100%) rename Python2/Hard/29.py => Python/Hard/72.py (100%) rename Python2/Hard/3.py => Python/Hard/73.py (100%) rename Python2/Hard/30.py => Python/Hard/74.py (100%) rename Python2/Hard/31.py => Python/Hard/75.py (100%) rename Python2/Hard/32.py => Python/Hard/76.py (100%) rename Python2/Hard/33.py => Python/Hard/77.py (100%) rename Python2/Hard/34.py => Python/Hard/78.py (100%) rename Python2/Hard/35.py => Python/Hard/79.py (100%) rename Python2/Hard/36.py => Python/Hard/80.py (100%) rename Python2/Hard/37.py => Python/Hard/81.py (100%) rename Python2/Hard/38.py => Python/Hard/82.py (100%) rename Python2/Hard/39.py => Python/Hard/83.py (100%) rename Python2/Hard/4.py => Python/Hard/84.py (100%) rename Python2/Hard/40.py => Python/Hard/85.py (100%) rename Python2/Hard/41.py => Python/Hard/86.py (100%) rename Python2/Hard/42.py => Python/Hard/87.py (100%) rename Python2/Hard/43.py => Python/Hard/88.py (100%) rename Python2/Hard/44.py => Python/Hard/89.py (100%) rename Python2/Hard/45.py => Python/Hard/90.py (100%) rename Python2/Hard/46.py => Python/Hard/91.py (100%) rename Python2/Hard/47.py => Python/Hard/92.py (100%) rename Python2/Hard/48.py => Python/Hard/93.py (100%) rename Python2/Hard/49.py => Python/Hard/94.py (100%) rename Python2/Hard/5.py => Python/Hard/95.py (100%) rename Python2/Hard/50.py => Python/Hard/96.py (100%) rename Python2/Hard/6.py => Python/Hard/97.py (100%) rename Python2/Hard/7.py => Python/Hard/98.py (100%) rename Python2/Hard/8.py => Python/Hard/99.py (100%) rename Python2/Medium/9.py => Python/Medium/100.py (100%) rename Python2/Medium/1.py => Python/Medium/51.py (100%) rename Python2/Medium/11.py => Python/Medium/53.py (100%) rename Python2/Medium/12.py => Python/Medium/54.py (100%) rename Python2/Medium/14.py => Python/Medium/56.py (100%) rename Python2/Medium/15.py => Python/Medium/57.py (100%) rename Python2/Medium/16.py => Python/Medium/58.py (100%) rename Python2/Medium/17.py => Python/Medium/59.py (100%) rename Python2/Medium/18.py => Python/Medium/60.py (100%) rename Python2/Medium/2.py => Python/Medium/62.py (100%) rename Python2/Medium/20.py => Python/Medium/63.py (100%) rename Python2/Medium/21.py => Python/Medium/64.py (100%) rename Python2/Medium/23.py => Python/Medium/66.py (100%) rename Python2/Medium/24.py => Python/Medium/67.py (100%) rename Python2/Medium/25.py => Python/Medium/68.py (100%) rename Python2/Medium/27.py => Python/Medium/70.py (100%) rename Python2/Medium/28.py => Python/Medium/71.py (100%) rename Python2/Medium/29.py => Python/Medium/72.py (100%) rename Python2/Medium/30.py => Python/Medium/74.py (100%) rename Python2/Medium/33.py => Python/Medium/77.py (100%) rename Python2/Medium/34.py => Python/Medium/78.py (100%) rename Python2/Medium/36.py => Python/Medium/80.py (100%) rename Python2/Medium/38.py => Python/Medium/82.py (100%) rename Python2/Medium/39.py => Python/Medium/83.py (100%) rename Python2/Medium/4.py => Python/Medium/84.py (100%) rename Python2/Medium/40.py => Python/Medium/85.py (100%) rename Python2/Medium/41.py => Python/Medium/86.py (100%) rename Python2/Medium/42.py => Python/Medium/87.py (100%) rename Python2/Medium/43.py => Python/Medium/88.py (100%) rename Python2/Medium/44.py => Python/Medium/89.py (100%) rename Python2/Medium/45.py => Python/Medium/90.py (100%) rename Python2/Medium/46.py => Python/Medium/91.py (100%) rename Python2/Medium/47.py => Python/Medium/92.py (100%) rename Python2/Medium/49.py => Python/Medium/94.py (100%) rename Python2/Medium/5.py => Python/Medium/95.py (100%) rename Python2/Medium/6.py => Python/Medium/97.py (100%) delete mode 100644 Python2/Easy/temp.txt delete mode 100644 Python2/Hard/1.py delete mode 100644 Python2/Hard/10.py delete mode 100644 Python2/Hard/temp.txt delete mode 100644 Python2/Medium/10.py delete mode 100644 Python2/Medium/13.py delete mode 100644 Python2/Medium/19.py delete mode 100644 Python2/Medium/22.py delete mode 100644 Python2/Medium/26.py delete mode 100644 Python2/Medium/3.py delete mode 100644 Python2/Medium/31.py delete mode 100644 Python2/Medium/32.py delete mode 100644 Python2/Medium/35.py delete mode 100644 Python2/Medium/37.py delete mode 100644 Python2/Medium/48.py delete mode 100644 Python2/Medium/50.py delete mode 100644 Python2/Medium/7.py delete mode 100644 Python2/Medium/8.py delete mode 100644 Python2/Medium/temp.txt delete mode 100644 Python2/temp.txt diff --git a/Python2/Easy/9.py b/Python/Easy/100.py similarity index 100% rename from Python2/Easy/9.py rename to Python/Easy/100.py diff --git a/Python2/Easy/1.py b/Python/Easy/51.py similarity index 100% rename from Python2/Easy/1.py rename to Python/Easy/51.py diff --git a/Python2/Easy/10.py b/Python/Easy/52.py similarity index 100% rename from Python2/Easy/10.py rename to Python/Easy/52.py diff --git a/Python2/Easy/11.py b/Python/Easy/53.py similarity index 100% rename from Python2/Easy/11.py rename to Python/Easy/53.py diff --git a/Python2/Easy/12.py b/Python/Easy/54.py similarity index 100% rename from Python2/Easy/12.py rename to Python/Easy/54.py diff --git a/Python2/Easy/13.py b/Python/Easy/55.py similarity index 100% rename from Python2/Easy/13.py rename to Python/Easy/55.py diff --git a/Python2/Easy/14.py b/Python/Easy/56.py similarity index 100% rename from Python2/Easy/14.py rename to Python/Easy/56.py diff --git a/Python2/Easy/15.py b/Python/Easy/57.py similarity index 100% rename from Python2/Easy/15.py rename to Python/Easy/57.py diff --git a/Python2/Easy/16.py b/Python/Easy/58.py similarity index 100% rename from Python2/Easy/16.py rename to Python/Easy/58.py diff --git a/Python2/Easy/17.py b/Python/Easy/59.py similarity index 100% rename from Python2/Easy/17.py rename to Python/Easy/59.py diff --git a/Python2/Easy/18.py b/Python/Easy/60.py similarity index 100% rename from Python2/Easy/18.py rename to Python/Easy/60.py diff --git a/Python2/Easy/19.py b/Python/Easy/61.py similarity index 100% rename from Python2/Easy/19.py rename to Python/Easy/61.py diff --git a/Python2/Easy/2.py b/Python/Easy/62.py similarity index 100% rename from Python2/Easy/2.py rename to Python/Easy/62.py diff --git a/Python2/Easy/20.py b/Python/Easy/63.py similarity index 100% rename from Python2/Easy/20.py rename to Python/Easy/63.py diff --git a/Python2/Easy/21.py b/Python/Easy/64.py similarity index 100% rename from Python2/Easy/21.py rename to Python/Easy/64.py diff --git a/Python2/Easy/22.py b/Python/Easy/65.py similarity index 100% rename from Python2/Easy/22.py rename to Python/Easy/65.py diff --git a/Python2/Easy/23.py b/Python/Easy/66.py similarity index 100% rename from Python2/Easy/23.py rename to Python/Easy/66.py diff --git a/Python2/Easy/24.py b/Python/Easy/67.py similarity index 100% rename from Python2/Easy/24.py rename to Python/Easy/67.py diff --git a/Python2/Easy/25.py b/Python/Easy/68.py similarity index 100% rename from Python2/Easy/25.py rename to Python/Easy/68.py diff --git a/Python2/Easy/26.py b/Python/Easy/69.py similarity index 100% rename from Python2/Easy/26.py rename to Python/Easy/69.py diff --git a/Python2/Easy/27.py b/Python/Easy/70.py similarity index 100% rename from Python2/Easy/27.py rename to Python/Easy/70.py diff --git a/Python2/Easy/28.py b/Python/Easy/71.py similarity index 100% rename from Python2/Easy/28.py rename to Python/Easy/71.py diff --git a/Python2/Easy/29.py b/Python/Easy/72.py similarity index 100% rename from Python2/Easy/29.py rename to Python/Easy/72.py diff --git a/Python2/Easy/3.py b/Python/Easy/73.py similarity index 100% rename from Python2/Easy/3.py rename to Python/Easy/73.py diff --git a/Python2/Easy/30.py b/Python/Easy/74.py similarity index 100% rename from Python2/Easy/30.py rename to Python/Easy/74.py diff --git a/Python2/Easy/31.py b/Python/Easy/75.py similarity index 100% rename from Python2/Easy/31.py rename to Python/Easy/75.py diff --git a/Python2/Easy/32.py b/Python/Easy/76.py similarity index 100% rename from Python2/Easy/32.py rename to Python/Easy/76.py diff --git a/Python2/Easy/33.py b/Python/Easy/77.py similarity index 100% rename from Python2/Easy/33.py rename to Python/Easy/77.py diff --git a/Python2/Easy/34.py b/Python/Easy/78.py similarity index 100% rename from Python2/Easy/34.py rename to Python/Easy/78.py diff --git a/Python2/Easy/35.py b/Python/Easy/79.py similarity index 100% rename from Python2/Easy/35.py rename to Python/Easy/79.py diff --git a/Python2/Easy/36.py b/Python/Easy/80.py similarity index 100% rename from Python2/Easy/36.py rename to Python/Easy/80.py diff --git a/Python2/Easy/37.py b/Python/Easy/81.py similarity index 100% rename from Python2/Easy/37.py rename to Python/Easy/81.py diff --git a/Python2/Easy/38.py b/Python/Easy/82.py similarity index 100% rename from Python2/Easy/38.py rename to Python/Easy/82.py diff --git a/Python2/Easy/39.py b/Python/Easy/83.py similarity index 100% rename from Python2/Easy/39.py rename to Python/Easy/83.py diff --git a/Python2/Easy/4.py b/Python/Easy/84.py similarity index 100% rename from Python2/Easy/4.py rename to Python/Easy/84.py diff --git a/Python2/Easy/40.py b/Python/Easy/85.py similarity index 100% rename from Python2/Easy/40.py rename to Python/Easy/85.py diff --git a/Python2/Easy/41.py b/Python/Easy/86.py similarity index 100% rename from Python2/Easy/41.py rename to Python/Easy/86.py diff --git a/Python2/Easy/42.py b/Python/Easy/87.py similarity index 100% rename from Python2/Easy/42.py rename to Python/Easy/87.py diff --git a/Python2/Easy/43.py b/Python/Easy/88.py similarity index 100% rename from Python2/Easy/43.py rename to Python/Easy/88.py diff --git a/Python2/Easy/44.py b/Python/Easy/89.py similarity index 100% rename from Python2/Easy/44.py rename to Python/Easy/89.py diff --git a/Python2/Easy/45.py b/Python/Easy/90.py similarity index 100% rename from Python2/Easy/45.py rename to Python/Easy/90.py diff --git a/Python2/Easy/46.py b/Python/Easy/91.py similarity index 100% rename from Python2/Easy/46.py rename to Python/Easy/91.py diff --git a/Python2/Easy/47.py b/Python/Easy/92.py similarity index 100% rename from Python2/Easy/47.py rename to Python/Easy/92.py diff --git a/Python2/Easy/48.py b/Python/Easy/93.py similarity index 100% rename from Python2/Easy/48.py rename to Python/Easy/93.py diff --git a/Python2/Easy/49.py b/Python/Easy/94.py similarity index 100% rename from Python2/Easy/49.py rename to Python/Easy/94.py diff --git a/Python2/Easy/5.py b/Python/Easy/95.py similarity index 100% rename from Python2/Easy/5.py rename to Python/Easy/95.py diff --git a/Python2/Easy/50.py b/Python/Easy/96.py similarity index 100% rename from Python2/Easy/50.py rename to Python/Easy/96.py diff --git a/Python2/Easy/6.py b/Python/Easy/97.py similarity index 100% rename from Python2/Easy/6.py rename to Python/Easy/97.py diff --git a/Python2/Easy/7.py b/Python/Easy/98.py similarity index 100% rename from Python2/Easy/7.py rename to Python/Easy/98.py diff --git a/Python2/Easy/8.py b/Python/Easy/99.py similarity index 100% rename from Python2/Easy/8.py rename to Python/Easy/99.py diff --git a/Python2/Hard/9.py b/Python/Hard/100.py similarity index 100% rename from Python2/Hard/9.py rename to Python/Hard/100.py diff --git a/Python/Hard/51.py b/Python/Hard/51.py index a674cc93..43a1b346 100644 --- a/Python/Hard/51.py +++ b/Python/Hard/51.py @@ -1,24 +1,26 @@ -class TrieNode: - def __init__(self): - self.children = {} - self.is_end_of_word = False -class Trie: - def __init__(self): - self.root = TrieNode() - def insert(self, word): - node = self.root - for char in word: - if char not in node.children: - node.children[char] = TrieNode - node = node.children[char] - node.is_end_of_word = True - def search(self, word): - node = self.root - for char in word: - if char not in node.children: - return False - node = node.children[char] - return node.is_end_of_word -trie = Trie() -trie.insert("hello") -print(trie.search("hello")) +class CustomError(Exception): + pass + +def read_file(filename): + try: + with open(filename, 'r') as file: + data = file.read() + return process_data(data) + except FileNotFoundError: + raise CustomError(f"File {filename} not found") + except CustomError as e: + print(f"CustomError occurred: {e}") + +def process_data(data): + try: + numbers = [int(x) for x in data.split(",")] + return calculate_average(numbers) + except ValueError: + raise CustomError("Data contains non-numeric values") + +def calculate_average(numbers): + return sum(numbers) / len(numbers) + +filename = "data.txt" +result = read_file(filename) +print("Average:", result) \ No newline at end of file diff --git a/Python/Hard/52.py b/Python/Hard/52.py index d3c316ad..61703f1f 100644 --- a/Python/Hard/52.py +++ b/Python/Hard/52.py @@ -1,17 +1,54 @@ -def bfs(graph, start): - visited = set() - queue = [(start, 0)] - level = {} - while queue: - node, depth = queue.pop() - if node not in visited: - visited.add(node) - level[node] = depth - - for neighbor in graph[node]: - if neighbor not in visited: - queue.append((neighbor, depth)) - return level - -graph = {1: [2, 3], 2: [4], 3: [5], 4: [], 5: []} -print(bfs(graph, 1)) \ No newline at end of file +import random +import numpy as np + +def fibonacci(n): + if not isinstance(n, int): + raise TypeError("Input must be an integer") + if n == 0: + return 0 + elif n == 1: + return 1 + elif n < 0: + return fibonacci(n + 2) - fibonacci(n + 1) + else: + return fibonacci(n - 1) + fibonacci(n - 2) + +def calculate_average(fib_sequence): + try: + avg = np.mean(fib_sequence) + if avg > 15: + raise OverflowError("Average value exceeds acceptable threshold.") + except OverflowError: + print("Caught OverflowError due to high average value.") + return avg + +def main(): + try: + num = random.choice([-5, 'ten', 8.5, None]) + if num < 0: + raise ValueError("Fibonacci sequence is not defined for negative numbers") + + result = fibonacci(num) + print(f"Fibonacci({num}) = {result}") + + reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (3, num // 3)) + print("Reshaped Fibonacci series:", reshaped_result) + + avg_result = calculate_average([fibonacci(i) for i in range(-5, num)]) + print("Average of Fibonacci series:", avg_result) + + except TypeError as e: + print(f"Caught a TypeError: {e}") + except ValueError: + print("Caught ValueError.") + except RecursionError: + print("Maximum recursion depth exceeded.") + except OverflowError: + print("Caught unexpected overflow error.") + finally: + invalid_result = str(fibonacci(3)) + None + print("Invalid concatenation result:", invalid_result) + + print("Shape of reshaped result:", reshaped_result.shape) + +main() diff --git a/Python2/Hard/11.py b/Python/Hard/53.py similarity index 100% rename from Python2/Hard/11.py rename to Python/Hard/53.py diff --git a/Python2/Hard/12.py b/Python/Hard/54.py similarity index 100% rename from Python2/Hard/12.py rename to Python/Hard/54.py diff --git a/Python2/Hard/13.py b/Python/Hard/55.py similarity index 100% rename from Python2/Hard/13.py rename to Python/Hard/55.py diff --git a/Python2/Hard/14.py b/Python/Hard/56.py similarity index 100% rename from Python2/Hard/14.py rename to Python/Hard/56.py diff --git a/Python2/Hard/15.py b/Python/Hard/57.py similarity index 100% rename from Python2/Hard/15.py rename to Python/Hard/57.py diff --git a/Python2/Hard/16.py b/Python/Hard/58.py similarity index 100% rename from Python2/Hard/16.py rename to Python/Hard/58.py diff --git a/Python2/Hard/17.py b/Python/Hard/59.py similarity index 100% rename from Python2/Hard/17.py rename to Python/Hard/59.py diff --git a/Python2/Hard/18.py b/Python/Hard/60.py similarity index 100% rename from Python2/Hard/18.py rename to Python/Hard/60.py diff --git a/Python2/Hard/19.py b/Python/Hard/61.py similarity index 100% rename from Python2/Hard/19.py rename to Python/Hard/61.py diff --git a/Python2/Hard/2.py b/Python/Hard/62.py similarity index 100% rename from Python2/Hard/2.py rename to Python/Hard/62.py diff --git a/Python2/Hard/20.py b/Python/Hard/63.py similarity index 100% rename from Python2/Hard/20.py rename to Python/Hard/63.py diff --git a/Python2/Hard/21.py b/Python/Hard/64.py similarity index 100% rename from Python2/Hard/21.py rename to Python/Hard/64.py diff --git a/Python2/Hard/22.py b/Python/Hard/65.py similarity index 100% rename from Python2/Hard/22.py rename to Python/Hard/65.py diff --git a/Python2/Hard/23.py b/Python/Hard/66.py similarity index 100% rename from Python2/Hard/23.py rename to Python/Hard/66.py diff --git a/Python2/Hard/24.py b/Python/Hard/67.py similarity index 100% rename from Python2/Hard/24.py rename to Python/Hard/67.py diff --git a/Python2/Hard/25.py b/Python/Hard/68.py similarity index 100% rename from Python2/Hard/25.py rename to Python/Hard/68.py diff --git a/Python2/Hard/26.py b/Python/Hard/69.py similarity index 100% rename from Python2/Hard/26.py rename to Python/Hard/69.py diff --git a/Python2/Hard/27.py b/Python/Hard/70.py similarity index 100% rename from Python2/Hard/27.py rename to Python/Hard/70.py diff --git a/Python2/Hard/28.py b/Python/Hard/71.py similarity index 100% rename from Python2/Hard/28.py rename to Python/Hard/71.py diff --git a/Python2/Hard/29.py b/Python/Hard/72.py similarity index 100% rename from Python2/Hard/29.py rename to Python/Hard/72.py diff --git a/Python2/Hard/3.py b/Python/Hard/73.py similarity index 100% rename from Python2/Hard/3.py rename to Python/Hard/73.py diff --git a/Python2/Hard/30.py b/Python/Hard/74.py similarity index 100% rename from Python2/Hard/30.py rename to Python/Hard/74.py diff --git a/Python2/Hard/31.py b/Python/Hard/75.py similarity index 100% rename from Python2/Hard/31.py rename to Python/Hard/75.py diff --git a/Python2/Hard/32.py b/Python/Hard/76.py similarity index 100% rename from Python2/Hard/32.py rename to Python/Hard/76.py diff --git a/Python2/Hard/33.py b/Python/Hard/77.py similarity index 100% rename from Python2/Hard/33.py rename to Python/Hard/77.py diff --git a/Python2/Hard/34.py b/Python/Hard/78.py similarity index 100% rename from Python2/Hard/34.py rename to Python/Hard/78.py diff --git a/Python2/Hard/35.py b/Python/Hard/79.py similarity index 100% rename from Python2/Hard/35.py rename to Python/Hard/79.py diff --git a/Python2/Hard/36.py b/Python/Hard/80.py similarity index 100% rename from Python2/Hard/36.py rename to Python/Hard/80.py diff --git a/Python2/Hard/37.py b/Python/Hard/81.py similarity index 100% rename from Python2/Hard/37.py rename to Python/Hard/81.py diff --git a/Python2/Hard/38.py b/Python/Hard/82.py similarity index 100% rename from Python2/Hard/38.py rename to Python/Hard/82.py diff --git a/Python2/Hard/39.py b/Python/Hard/83.py similarity index 100% rename from Python2/Hard/39.py rename to Python/Hard/83.py diff --git a/Python2/Hard/4.py b/Python/Hard/84.py similarity index 100% rename from Python2/Hard/4.py rename to Python/Hard/84.py diff --git a/Python2/Hard/40.py b/Python/Hard/85.py similarity index 100% rename from Python2/Hard/40.py rename to Python/Hard/85.py diff --git a/Python2/Hard/41.py b/Python/Hard/86.py similarity index 100% rename from Python2/Hard/41.py rename to Python/Hard/86.py diff --git a/Python2/Hard/42.py b/Python/Hard/87.py similarity index 100% rename from Python2/Hard/42.py rename to Python/Hard/87.py diff --git a/Python2/Hard/43.py b/Python/Hard/88.py similarity index 100% rename from Python2/Hard/43.py rename to Python/Hard/88.py diff --git a/Python2/Hard/44.py b/Python/Hard/89.py similarity index 100% rename from Python2/Hard/44.py rename to Python/Hard/89.py diff --git a/Python2/Hard/45.py b/Python/Hard/90.py similarity index 100% rename from Python2/Hard/45.py rename to Python/Hard/90.py diff --git a/Python2/Hard/46.py b/Python/Hard/91.py similarity index 100% rename from Python2/Hard/46.py rename to Python/Hard/91.py diff --git a/Python2/Hard/47.py b/Python/Hard/92.py similarity index 100% rename from Python2/Hard/47.py rename to Python/Hard/92.py diff --git a/Python2/Hard/48.py b/Python/Hard/93.py similarity index 100% rename from Python2/Hard/48.py rename to Python/Hard/93.py diff --git a/Python2/Hard/49.py b/Python/Hard/94.py similarity index 100% rename from Python2/Hard/49.py rename to Python/Hard/94.py diff --git a/Python2/Hard/5.py b/Python/Hard/95.py similarity index 100% rename from Python2/Hard/5.py rename to Python/Hard/95.py diff --git a/Python2/Hard/50.py b/Python/Hard/96.py similarity index 100% rename from Python2/Hard/50.py rename to Python/Hard/96.py diff --git a/Python2/Hard/6.py b/Python/Hard/97.py similarity index 100% rename from Python2/Hard/6.py rename to Python/Hard/97.py diff --git a/Python2/Hard/7.py b/Python/Hard/98.py similarity index 100% rename from Python2/Hard/7.py rename to Python/Hard/98.py diff --git a/Python2/Hard/8.py b/Python/Hard/99.py similarity index 100% rename from Python2/Hard/8.py rename to Python/Hard/99.py diff --git a/Python2/Medium/9.py b/Python/Medium/100.py similarity index 100% rename from Python2/Medium/9.py rename to Python/Medium/100.py diff --git a/Python2/Medium/1.py b/Python/Medium/51.py similarity index 100% rename from Python2/Medium/1.py rename to Python/Medium/51.py diff --git a/Python/Medium/52.py b/Python/Medium/52.py index 06de13ee..fb8d2ebc 100644 --- a/Python/Medium/52.py +++ b/Python/Medium/52.py @@ -1,7 +1,9 @@ -x = 15 -if x > 10: - print("x is greater than 10") -else: - print("x is less than or equal to 10") -elif x == 15: - print("x is equal to 15") +def append_to_list(item, lst=[]): + lst.append(item) + return lst + def main(): + list1 = append_to_list(1) + print(f"List after first append: {list1}") + list2 = append_to_list(2) + print(f"List after second append: {list2}") + main() \ No newline at end of file diff --git a/Python2/Medium/11.py b/Python/Medium/53.py similarity index 100% rename from Python2/Medium/11.py rename to Python/Medium/53.py diff --git a/Python2/Medium/12.py b/Python/Medium/54.py similarity index 100% rename from Python2/Medium/12.py rename to Python/Medium/54.py diff --git a/Python/Medium/55.py b/Python/Medium/55.py index 8a876ea9..bf4b1690 100644 --- a/Python/Medium/55.py +++ b/Python/Medium/55.py @@ -1,3 +1,13 @@ -try: - value = int("abc") -print("This won't execute") + def concatenate_strings(lst): + result = "" + for item in lst: + result += item + return result + def main(): + items = ["Hello", " ", 123, "World!"] + try: + result = concatenate_strings(items) + print(result) + except TypeError as e: + print(f"TypeError: {e}") + main() \ No newline at end of file diff --git a/Python2/Medium/14.py b/Python/Medium/56.py similarity index 100% rename from Python2/Medium/14.py rename to Python/Medium/56.py diff --git a/Python2/Medium/15.py b/Python/Medium/57.py similarity index 100% rename from Python2/Medium/15.py rename to Python/Medium/57.py diff --git a/Python2/Medium/16.py b/Python/Medium/58.py similarity index 100% rename from Python2/Medium/16.py rename to Python/Medium/58.py diff --git a/Python2/Medium/17.py b/Python/Medium/59.py similarity index 100% rename from Python2/Medium/17.py rename to Python/Medium/59.py diff --git a/Python2/Medium/18.py b/Python/Medium/60.py similarity index 100% rename from Python2/Medium/18.py rename to Python/Medium/60.py diff --git a/Python/Medium/61.py b/Python/Medium/61.py index 961eeca6..bd2cef5f 100644 --- a/Python/Medium/61.py +++ b/Python/Medium/61.py @@ -1,12 +1,14 @@ -def print_numbers(): - - for i in range[1, 6]: - - print i) - - i += 1 - - print("Final value of i:", i) - - -print_numbers() +def is_prime(n): + if n < 2: + return False + for i in range(2, n // 2): + if n % i == 0: + return False + return True + def main(): + number = 15 +if is_prime(number): + print(f"{number} is a prime number") + else: + print(f"{number} is not a prime number") + main() \ No newline at end of file diff --git a/Python2/Medium/2.py b/Python/Medium/62.py similarity index 100% rename from Python2/Medium/2.py rename to Python/Medium/62.py diff --git a/Python2/Medium/20.py b/Python/Medium/63.py similarity index 100% rename from Python2/Medium/20.py rename to Python/Medium/63.py diff --git a/Python2/Medium/21.py b/Python/Medium/64.py similarity index 100% rename from Python2/Medium/21.py rename to Python/Medium/64.py diff --git a/Python/Medium/65.py b/Python/Medium/65.py index 95e63917..51e48574 100644 --- a/Python/Medium/65.py +++ b/Python/Medium/65.py @@ -1,23 +1,9 @@ - -def check_numbers(): - - for i in range("5"): - - - print i - - - if i = "5": - - print("Finally reached five, which shouldn't be possible!") - - - break i - - j + 1 - - - print("Loop ended at:", i) - - -check_numbers() + class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): +self.salary += amount + employee = Employee('John', 50000) + employee.give_raise('5000') + print(employee.salary) \ No newline at end of file diff --git a/Python2/Medium/23.py b/Python/Medium/66.py similarity index 100% rename from Python2/Medium/23.py rename to Python/Medium/66.py diff --git a/Python2/Medium/24.py b/Python/Medium/67.py similarity index 100% rename from Python2/Medium/24.py rename to Python/Medium/67.py diff --git a/Python2/Medium/25.py b/Python/Medium/68.py similarity index 100% rename from Python2/Medium/25.py rename to Python/Medium/68.py diff --git a/Python/Medium/69.py b/Python/Medium/69.py index b1b73360..549796e5 100644 --- a/Python/Medium/69.py +++ b/Python/Medium/69.py @@ -1,28 +1,12 @@ -x = 10 -y = "5" +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + def __eq__(self, other): + return self.title == other.title and self.author == other.author -if x > 5: - if y > 3: - print("y is greater than 3") - elif x == 10: - print("x is exactly 10") - else: - print("This won't be printed, but it's here anyway") +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" -elif x < 5: - print("x is less than 5") - - -else: - print("x is exactly 5") - - -if x == "10": - print("x is string 10") - -if y == 5: - print("y is integer 5") - -else: - print("No match for y") +print(book1 == book2) diff --git a/Python2/Medium/27.py b/Python/Medium/70.py similarity index 100% rename from Python2/Medium/27.py rename to Python/Medium/70.py diff --git a/Python2/Medium/28.py b/Python/Medium/71.py similarity index 100% rename from Python2/Medium/28.py rename to Python/Medium/71.py diff --git a/Python2/Medium/29.py b/Python/Medium/72.py similarity index 100% rename from Python2/Medium/29.py rename to Python/Medium/72.py diff --git a/Python/Medium/73.py b/Python/Medium/73.py index f13cd1f8..efab262b 100644 --- a/Python/Medium/73.py +++ b/Python/Medium/73.py @@ -1,3 +1,10 @@ -list1 = [1, 2, 3] -list2 = [4, 5, 6] -list1 += list2() + def countdown(n): + while n >= 0: + print(n) + n += 1 + def main(): + try: + countdown(5) + except KeyboardInterrupt: + print("Countdown interrupted") +main() \ No newline at end of file diff --git a/Python2/Medium/30.py b/Python/Medium/74.py similarity index 100% rename from Python2/Medium/30.py rename to Python/Medium/74.py diff --git a/Python/Medium/75.py b/Python/Medium/75.py index fd719455..3b8bc447 100644 --- a/Python/Medium/75.py +++ b/Python/Medium/75.py @@ -1,4 +1,8 @@ -try: - result = 10 / 0 -finally: - print("This is printed after the exception") +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.grade()) diff --git a/Python/Medium/76.py b/Python/Medium/76.py index 7f99ef07..b4208ffb 100644 --- a/Python/Medium/76.py +++ b/Python/Medium/76.py @@ -1,16 +1,12 @@ - -x = 10 + 2 * 3 ** 2 - - -y = 5 + 3 ** 2 * 2 - (4 / 2) + 1 - - -x = "Value: " + str(x) - - -z = x + 10 * 2 - - -print("Final value of x:", x) -print("Value of y:", y) -print("Value of z:", z) \ No newline at end of file +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') +ne '=' + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') diff --git a/Python2/Medium/33.py b/Python/Medium/77.py similarity index 100% rename from Python2/Medium/33.py rename to Python/Medium/77.py diff --git a/Python2/Medium/34.py b/Python/Medium/78.py similarity index 100% rename from Python2/Medium/34.py rename to Python/Medium/78.py diff --git a/Python/Medium/79.py b/Python/Medium/79.py index eed734dc..968cef11 100644 --- a/Python/Medium/79.py +++ b/Python/Medium/79.py @@ -1,19 +1,10 @@ -def multiply(a, b): - return a * b - - -result = multiply(2, 3) + multiply(2, '4') - - -print(result + undefined_variable) - - -if multiply(5, 0) = 0: - print("This won't print due to syntax error") - - -for i in range(5) - print("Loop iteration:", i) - - -print("Final result is:", result, "with multiplication check:", multiply(4, 'five')) +def sum_of_elements(lst): + total = 0 + for i in range(len(lst)): + total += lst[i + 1] + return total +def main(): + numbers = [1, 2, 3, 4] + result = sum_of_elements(numbers) + print(f"Sum: {result}") +main() diff --git a/Python2/Medium/36.py b/Python/Medium/80.py similarity index 100% rename from Python2/Medium/36.py rename to Python/Medium/80.py diff --git a/Python/Medium/81.py b/Python/Medium/81.py index 5b88cf1c..c808e037 100644 --- a/Python/Medium/81.py +++ b/Python/Medium/81.py @@ -1,24 +1,23 @@ -def outer(): - def inner(): - print(x) - inner() - - -x = "5" - - -def another_function(): - print("This is another function.") - inner() - -outer() - - -def yet_another_function(): - global x - x = x + 1 - -yet_another_function() - - -print("Final value of x is: " + x) +def factorial(n): + if n < 0: + return None + result = 1 + while n >= 1: + result *= n + n += 1 + return result + +def memoized_factorial(n, cache={}): + if n in cache: + return cache[n] + if n == 0 or n == 1: + return 1 + cache[n] = n * memoized_factorial(n - 1) + return cache[n] + +def main(): + number = 5 + print(f"Factorial of {number}: {factorial(number)}") + print(f"Memoized Factorial of {number}: {memoized_factorial(number)}") + print(f"Factorial of -1: {factorial(-1)}") +main() diff --git a/Python2/Medium/38.py b/Python/Medium/82.py similarity index 100% rename from Python2/Medium/38.py rename to Python/Medium/82.py diff --git a/Python2/Medium/39.py b/Python/Medium/83.py similarity index 100% rename from Python2/Medium/39.py rename to Python/Medium/83.py diff --git a/Python2/Medium/4.py b/Python/Medium/84.py similarity index 100% rename from Python2/Medium/4.py rename to Python/Medium/84.py diff --git a/Python2/Medium/40.py b/Python/Medium/85.py similarity index 100% rename from Python2/Medium/40.py rename to Python/Medium/85.py diff --git a/Python2/Medium/41.py b/Python/Medium/86.py similarity index 100% rename from Python2/Medium/41.py rename to Python/Medium/86.py diff --git a/Python2/Medium/42.py b/Python/Medium/87.py similarity index 100% rename from Python2/Medium/42.py rename to Python/Medium/87.py diff --git a/Python2/Medium/43.py b/Python/Medium/88.py similarity index 100% rename from Python2/Medium/43.py rename to Python/Medium/88.py diff --git a/Python2/Medium/44.py b/Python/Medium/89.py similarity index 100% rename from Python2/Medium/44.py rename to Python/Medium/89.py diff --git a/Python2/Medium/45.py b/Python/Medium/90.py similarity index 100% rename from Python2/Medium/45.py rename to Python/Medium/90.py diff --git a/Python2/Medium/46.py b/Python/Medium/91.py similarity index 100% rename from Python2/Medium/46.py rename to Python/Medium/91.py diff --git a/Python2/Medium/47.py b/Python/Medium/92.py similarity index 100% rename from Python2/Medium/47.py rename to Python/Medium/92.py diff --git a/Python/Medium/93.py b/Python/Medium/93.py index ac22c448..2f48ec83 100644 --- a/Python/Medium/93.py +++ b/Python/Medium/93.py @@ -1,3 +1,15 @@ -x = 10 -y = 10 -if x is y: print("Same") +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n - 1) + fibonacci(n - 2) +def main(): +try: +Intermediate Level Code Snippets 18 + result = fibonacci(-3) + print(f"Fibonacci: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") +main() diff --git a/Python2/Medium/49.py b/Python/Medium/94.py similarity index 100% rename from Python2/Medium/49.py rename to Python/Medium/94.py diff --git a/Python2/Medium/5.py b/Python/Medium/95.py similarity index 100% rename from Python2/Medium/5.py rename to Python/Medium/95.py diff --git a/Python/Medium/96.py b/Python/Medium/96.py index 76e8ff0e..61a9b882 100644 --- a/Python/Medium/96.py +++ b/Python/Medium/96.py @@ -1,10 +1,7 @@ -my_list = [1, 2, 3, 4, -5, 6, 7 8, 9] - -my_dict = { - 'key1': 1, - 'key2': 2, - 'key3': 3, - 'key4': 4 - 'key5': 5 -} +def sort_dict_by_values(d): + return sorted(d, key=lambda x: x[1]) +def main(): + my_dict = {'a': 3, 'b': 1, 'c': 2} + result = sort_dict_by_values(my_dict) + print(f"Sorted dictionary: {result}") +main() diff --git a/Python2/Medium/6.py b/Python/Medium/97.py similarity index 100% rename from Python2/Medium/6.py rename to Python/Medium/97.py diff --git a/Python/Medium/98.py b/Python/Medium/98.py index 2a6c4a08..1de7cf1a 100644 --- a/Python/Medium/98.py +++ b/Python/Medium/98.py @@ -1,5 +1,11 @@ -x = 10 -else: - print("x is something else") -x = 5 -continue +def safe_divide(a, b): + if b == 0: + return "Cannot divide by zero" + return a / b + def main(): + try: + print(safe_divide(10, 0)) + print(safe_divide(0, 0)) + except ZeroDivisionError as e: + print(f"ZeroDivisionError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/99.py b/Python/Medium/99.py index ca7f87a9..6b4ab2f8 100644 --- a/Python/Medium/99.py +++ b/Python/Medium/99.py @@ -1,2 +1,12 @@ -squared = [x**2 for x in range(10) if x > 2 print(x)] -evens = [x for x in range(20) if x % 2 == 0 print(x)] +def get_value(d, key): + try: + return d[key] + except KeyError as e: + print(f"KeyError: {e}") + return None + def main(): + my_dict = {"a": 1, "b": 2} + value = get_value(my_dict, "c") + if value is not None: + print(f"Value for key 'c': {value}") + main() \ No newline at end of file diff --git a/Python2/Easy/temp.txt b/Python2/Easy/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/Python2/Easy/temp.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Python2/Hard/1.py b/Python2/Hard/1.py deleted file mode 100644 index 43a1b346..00000000 --- a/Python2/Hard/1.py +++ /dev/null @@ -1,26 +0,0 @@ -class CustomError(Exception): - pass - -def read_file(filename): - try: - with open(filename, 'r') as file: - data = file.read() - return process_data(data) - except FileNotFoundError: - raise CustomError(f"File {filename} not found") - except CustomError as e: - print(f"CustomError occurred: {e}") - -def process_data(data): - try: - numbers = [int(x) for x in data.split(",")] - return calculate_average(numbers) - except ValueError: - raise CustomError("Data contains non-numeric values") - -def calculate_average(numbers): - return sum(numbers) / len(numbers) - -filename = "data.txt" -result = read_file(filename) -print("Average:", result) \ No newline at end of file diff --git a/Python2/Hard/10.py b/Python2/Hard/10.py deleted file mode 100644 index 61703f1f..00000000 --- a/Python2/Hard/10.py +++ /dev/null @@ -1,54 +0,0 @@ -import random -import numpy as np - -def fibonacci(n): - if not isinstance(n, int): - raise TypeError("Input must be an integer") - if n == 0: - return 0 - elif n == 1: - return 1 - elif n < 0: - return fibonacci(n + 2) - fibonacci(n + 1) - else: - return fibonacci(n - 1) + fibonacci(n - 2) - -def calculate_average(fib_sequence): - try: - avg = np.mean(fib_sequence) - if avg > 15: - raise OverflowError("Average value exceeds acceptable threshold.") - except OverflowError: - print("Caught OverflowError due to high average value.") - return avg - -def main(): - try: - num = random.choice([-5, 'ten', 8.5, None]) - if num < 0: - raise ValueError("Fibonacci sequence is not defined for negative numbers") - - result = fibonacci(num) - print(f"Fibonacci({num}) = {result}") - - reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (3, num // 3)) - print("Reshaped Fibonacci series:", reshaped_result) - - avg_result = calculate_average([fibonacci(i) for i in range(-5, num)]) - print("Average of Fibonacci series:", avg_result) - - except TypeError as e: - print(f"Caught a TypeError: {e}") - except ValueError: - print("Caught ValueError.") - except RecursionError: - print("Maximum recursion depth exceeded.") - except OverflowError: - print("Caught unexpected overflow error.") - finally: - invalid_result = str(fibonacci(3)) + None - print("Invalid concatenation result:", invalid_result) - - print("Shape of reshaped result:", reshaped_result.shape) - -main() diff --git a/Python2/Hard/temp.txt b/Python2/Hard/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/Python2/Hard/temp.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Python2/Medium/10.py b/Python2/Medium/10.py deleted file mode 100644 index fb8d2ebc..00000000 --- a/Python2/Medium/10.py +++ /dev/null @@ -1,9 +0,0 @@ -def append_to_list(item, lst=[]): - lst.append(item) - return lst - def main(): - list1 = append_to_list(1) - print(f"List after first append: {list1}") - list2 = append_to_list(2) - print(f"List after second append: {list2}") - main() \ No newline at end of file diff --git a/Python2/Medium/13.py b/Python2/Medium/13.py deleted file mode 100644 index bf4b1690..00000000 --- a/Python2/Medium/13.py +++ /dev/null @@ -1,13 +0,0 @@ - def concatenate_strings(lst): - result = "" - for item in lst: - result += item - return result - def main(): - items = ["Hello", " ", 123, "World!"] - try: - result = concatenate_strings(items) - print(result) - except TypeError as e: - print(f"TypeError: {e}") - main() \ No newline at end of file diff --git a/Python2/Medium/19.py b/Python2/Medium/19.py deleted file mode 100644 index bd2cef5f..00000000 --- a/Python2/Medium/19.py +++ /dev/null @@ -1,14 +0,0 @@ -def is_prime(n): - if n < 2: - return False - for i in range(2, n // 2): - if n % i == 0: - return False - return True - def main(): - number = 15 -if is_prime(number): - print(f"{number} is a prime number") - else: - print(f"{number} is not a prime number") - main() \ No newline at end of file diff --git a/Python2/Medium/22.py b/Python2/Medium/22.py deleted file mode 100644 index 51e48574..00000000 --- a/Python2/Medium/22.py +++ /dev/null @@ -1,9 +0,0 @@ - class Employee: - def __init__(self, name, salary): - self.name = name - self.salary = salary - def give_raise(self, amount): -self.salary += amount - employee = Employee('John', 50000) - employee.give_raise('5000') - print(employee.salary) \ No newline at end of file diff --git a/Python2/Medium/26.py b/Python2/Medium/26.py deleted file mode 100644 index 549796e5..00000000 --- a/Python2/Medium/26.py +++ /dev/null @@ -1,12 +0,0 @@ -class Book: - def __init__(self, title, author): - self.title = title - self.author = author - - def __eq__(self, other): - return self.title == other.title and self.author == other.author - -book1 = Book('Python Programming', 'John Doe') -book2 = "Python Programming" - -print(book1 == book2) diff --git a/Python2/Medium/3.py b/Python2/Medium/3.py deleted file mode 100644 index efab262b..00000000 --- a/Python2/Medium/3.py +++ /dev/null @@ -1,10 +0,0 @@ - def countdown(n): - while n >= 0: - print(n) - n += 1 - def main(): - try: - countdown(5) - except KeyboardInterrupt: - print("Countdown interrupted") -main() \ No newline at end of file diff --git a/Python2/Medium/31.py b/Python2/Medium/31.py deleted file mode 100644 index 3b8bc447..00000000 --- a/Python2/Medium/31.py +++ /dev/null @@ -1,8 +0,0 @@ -class Student: - def __init__(self, name, grade): - self.name = name - self.grade = grade - def __str__(self): - return f'{self.name} ({self.grade})' -student = Student('Alice', 90) -print(student.grade()) diff --git a/Python2/Medium/32.py b/Python2/Medium/32.py deleted file mode 100644 index b4208ffb..00000000 --- a/Python2/Medium/32.py +++ /dev/null @@ -1,12 +0,0 @@ -def read_config(filename): - config = {} - try: - with open(filename, 'r') as file: - for line in file: - key, value = line.strip().split('=') -ne '=' - config[key] = value - except FileNotFoundError: - print('Config file not found') - return config -result = read_config('config.txt') diff --git a/Python2/Medium/35.py b/Python2/Medium/35.py deleted file mode 100644 index 968cef11..00000000 --- a/Python2/Medium/35.py +++ /dev/null @@ -1,10 +0,0 @@ -def sum_of_elements(lst): - total = 0 - for i in range(len(lst)): - total += lst[i + 1] - return total -def main(): - numbers = [1, 2, 3, 4] - result = sum_of_elements(numbers) - print(f"Sum: {result}") -main() diff --git a/Python2/Medium/37.py b/Python2/Medium/37.py deleted file mode 100644 index c808e037..00000000 --- a/Python2/Medium/37.py +++ /dev/null @@ -1,23 +0,0 @@ -def factorial(n): - if n < 0: - return None - result = 1 - while n >= 1: - result *= n - n += 1 - return result - -def memoized_factorial(n, cache={}): - if n in cache: - return cache[n] - if n == 0 or n == 1: - return 1 - cache[n] = n * memoized_factorial(n - 1) - return cache[n] - -def main(): - number = 5 - print(f"Factorial of {number}: {factorial(number)}") - print(f"Memoized Factorial of {number}: {memoized_factorial(number)}") - print(f"Factorial of -1: {factorial(-1)}") -main() diff --git a/Python2/Medium/48.py b/Python2/Medium/48.py deleted file mode 100644 index 2f48ec83..00000000 --- a/Python2/Medium/48.py +++ /dev/null @@ -1,15 +0,0 @@ -def fibonacci(n): - if n == 0: - return 0 - elif n == 1: - return 1 - else: - return fibonacci(n - 1) + fibonacci(n - 2) -def main(): -try: -Intermediate Level Code Snippets 18 - result = fibonacci(-3) - print(f"Fibonacci: {result}") - except RecursionError as e: - print(f"RecursionError: {e}") -main() diff --git a/Python2/Medium/50.py b/Python2/Medium/50.py deleted file mode 100644 index 61a9b882..00000000 --- a/Python2/Medium/50.py +++ /dev/null @@ -1,7 +0,0 @@ -def sort_dict_by_values(d): - return sorted(d, key=lambda x: x[1]) -def main(): - my_dict = {'a': 3, 'b': 1, 'c': 2} - result = sort_dict_by_values(my_dict) - print(f"Sorted dictionary: {result}") -main() diff --git a/Python2/Medium/7.py b/Python2/Medium/7.py deleted file mode 100644 index 1de7cf1a..00000000 --- a/Python2/Medium/7.py +++ /dev/null @@ -1,11 +0,0 @@ -def safe_divide(a, b): - if b == 0: - return "Cannot divide by zero" - return a / b - def main(): - try: - print(safe_divide(10, 0)) - print(safe_divide(0, 0)) - except ZeroDivisionError as e: - print(f"ZeroDivisionError: {e}") - main() \ No newline at end of file diff --git a/Python2/Medium/8.py b/Python2/Medium/8.py deleted file mode 100644 index 6b4ab2f8..00000000 --- a/Python2/Medium/8.py +++ /dev/null @@ -1,12 +0,0 @@ -def get_value(d, key): - try: - return d[key] - except KeyError as e: - print(f"KeyError: {e}") - return None - def main(): - my_dict = {"a": 1, "b": 2} - value = get_value(my_dict, "c") - if value is not None: - print(f"Value for key 'c': {value}") - main() \ No newline at end of file diff --git a/Python2/Medium/temp.txt b/Python2/Medium/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/Python2/Medium/temp.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Python2/temp.txt b/Python2/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/Python2/temp.txt +++ /dev/null @@ -1 +0,0 @@ - From fdf94f18b4bd286a6116be2d687fa34176f5759f Mon Sep 17 00:00:00 2001 From: Ariyan-25 <167085284+Ariyan-25@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:22:29 +0530 Subject: [PATCH 33/62] ariyan2 --- Java/Easy/102.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/102.java b/Java/Easy/102.java index cd7935f4..0a69d3b4 100644 --- a/Java/Easy/102.java +++ b/Java/Easy/102.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { - for (int i = 0; i < 5) { + for (int i = 0; i < 5; i++) { System.out.println(i); } } From c3306a96b85c0865020754eea5baeeeb693295a9 Mon Sep 17 00:00:00 2001 From: Ariyan-25 <167085284+Ariyan-25@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:23:03 +0530 Subject: [PATCH 34/62] ariyan3 --- Java/Easy/105.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/105.java b/Java/Easy/105.java index 8439b171..ed89894e 100644 --- a/Java/Easy/105.java +++ b/Java/Easy/105.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { String text = "java"; - System.out.println(text.ToUpperCase()); + System.out.println(text.toUpperCase()); } } From f7ee43ae7517c2c2b6eaf67f503256c59a25f324 Mon Sep 17 00:00:00 2001 From: Ariyan-25 <167085284+Ariyan-25@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:35:54 +0530 Subject: [PATCH 35/62] ariyan4 --- Java/Easy/103.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Java/Easy/103.java b/Java/Easy/103.java index 624b5bed..92c1fa47 100644 --- a/Java/Easy/103.java +++ b/Java/Easy/103.java @@ -1,6 +1,9 @@ +import java.util.ArrayList; +import java.util.List; + class Main { public static void main(String[] args) { - List numbers = new ArrayList<>(); + List numbers = new ArrayList<>(); numbers.add(10); System.out.println(numbers.get(0)); } From 9c8da85d4f33638117331600c06c8cfc25b2fde9 Mon Sep 17 00:00:00 2001 From: OptimAssaSin <148183548+OptimAssaSin@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:41:03 +0530 Subject: [PATCH 36/62] easy --- C++/Easy/1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C++/Easy/1.cpp b/C++/Easy/1.cpp index a94d030e..7714bf2e 100644 --- a/C++/Easy/1.cpp +++ b/C++/Easy/1.cpp @@ -4,6 +4,6 @@ int main() { const int a = 10; b = 11; - a = 100; + b = 110; } From 6bbf525a4ab600f4e30a14d6b660d29a5ea045c9 Mon Sep 17 00:00:00 2001 From: OptimAssaSin <148183548+OptimAssaSin@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:41:46 +0530 Subject: [PATCH 37/62] easy --- C++/Easy/2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/C++/Easy/2.cpp b/C++/Easy/2.cpp index 2b420da2..c7f556aa 100644 --- a/C++/Easy/2.cpp +++ b/C++/Easy/2.cpp @@ -3,5 +3,6 @@ int main() { int a = 5; int a = 10; + c=10; return 0; } From 5b2402fff1903f74571031630bea4d8a6e363fb1 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Fri, 4 Oct 2024 23:49:33 +0530 Subject: [PATCH 38/62] Revert "easy" --- C++/Easy/2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/C++/Easy/2.cpp b/C++/Easy/2.cpp index c7f556aa..2b420da2 100644 --- a/C++/Easy/2.cpp +++ b/C++/Easy/2.cpp @@ -3,6 +3,5 @@ int main() { int a = 5; int a = 10; - c=10; return 0; } From 3c79620fd8a89dcff00729891345f1ba4a5455bf Mon Sep 17 00:00:00 2001 From: Whiskas101 Date: Sat, 5 Oct 2024 11:19:39 +0530 Subject: [PATCH 39/62] updated --- C++/Hard/1.cpp | 18 --------- C++/Hard/10.cpp | 38 ------------------- C++/Hard/11.cpp | 53 -------------------------- C++/Hard/12.cpp | 88 -------------------------------------------- C++/Hard/13.cpp | 43 ---------------------- C++/Hard/14.cpp | 23 ------------ C++/Hard/15.cpp | 25 ------------- C++/Hard/16.cpp | 30 --------------- C++/Hard/17.cpp | 29 --------------- C++/Hard/18.cpp | 15 -------- C++/Hard/19.cpp | 32 ---------------- C++/Hard/2.cpp | 58 ----------------------------- C++/Hard/20.cpp | 17 --------- C++/Hard/21.cpp | 27 -------------- C++/Hard/22.cpp | 16 -------- C++/Hard/23.cpp | 35 ------------------ C++/Hard/24.cpp | 29 --------------- C++/Hard/25.cpp | 16 -------- C++/Hard/26.cpp | 19 ---------- C++/Hard/27.cpp | 12 ------ C++/Hard/28.cpp | 13 ------- C++/Hard/29.cpp | 17 --------- C++/Hard/3.cpp | 19 ---------- C++/Hard/30.cpp | 10 ----- C++/Hard/31.cpp | 18 --------- C++/Hard/32.cpp | 20 ---------- C++/Hard/33.cpp | 13 ------- C++/Hard/34.cpp | 18 --------- C++/Hard/35.cpp | 22 ----------- C++/Hard/36.cpp | 26 ------------- C++/Hard/37.cpp | 25 ------------- C++/Hard/38.cpp | 27 -------------- C++/Hard/39.cpp | 16 -------- C++/Hard/4.cpp | 33 ----------------- C++/Hard/40.cpp | 26 ------------- C++/Hard/41.cpp | 14 ------- C++/Hard/42.cpp | 30 --------------- C++/Hard/43.cpp | 10 ----- C++/Hard/44.cpp | 13 ------- C++/Hard/45.cpp | 44 ---------------------- C++/Hard/46.cpp | 29 --------------- C++/Hard/47.cpp | 30 --------------- C++/Hard/48.cpp | 18 --------- C++/Hard/49.cpp | 30 --------------- C++/Hard/5.cpp | 26 ------------- C++/Hard/50.cpp | 20 ---------- C++/Hard/6.cpp | 35 ------------------ C++/Hard/7.cpp | 34 ----------------- C++/Hard/8.cpp | 27 -------------- C++/Hard/9.cpp | 43 ---------------------- Python/Hard/1.py | 9 ----- Python/Hard/10.py | 6 --- Python/Hard/100.py | 38 ------------------- Python/Hard/11.py | 3 -- Python/Hard/12.py | 4 -- Python/Hard/13.py | 3 -- Python/Hard/14.py | 6 --- Python/Hard/16.py | 5 --- Python/Hard/17.py | 7 ---- Python/Hard/18.py | 8 ---- Python/Hard/19.py | 10 ----- Python/Hard/2.py | 3 -- Python/Hard/20.py | 4 -- Python/Hard/21.py | 8 ---- Python/Hard/22.py | 6 --- Python/Hard/23.py | 10 ----- Python/Hard/24.py | 3 -- Python/Hard/25.py | 5 --- Python/Hard/26.py | 4 -- Python/Hard/27.py | 8 ---- Python/Hard/28.py | 4 -- Python/Hard/29.py | 5 --- Python/Hard/3.py | 3 -- Python/Hard/30.py | 5 --- Python/Hard/31.py | 3 -- Python/Hard/32.py | 3 -- Python/Hard/33.py | 5 --- Python/Hard/34.py | 7 ---- Python/Hard/35.py | 4 -- Python/Hard/36.py | 6 --- Python/Hard/37.py | 7 ---- Python/Hard/38.py | 3 -- Python/Hard/39.py | 6 --- Python/Hard/4.py | 4 -- Python/Hard/40.py | 4 -- Python/Hard/41.py | 2 - Python/Hard/42.py | 6 --- Python/Hard/43.py | 5 --- Python/Hard/44.py | 2 - Python/Hard/45.py | 4 -- Python/Hard/46.py | 11 ------ Python/Hard/47.py | 11 ------ Python/Hard/48.py | 12 ------ Python/Hard/49.py | 24 ------------ Python/Hard/5.py | 4 -- Python/Hard/50.py | 13 ------- Python/Hard/51.py | 26 ------------- Python/Hard/52.py | 54 --------------------------- Python/Hard/53.py | 65 -------------------------------- Python/Hard/54.py | 23 ------------ Python/Hard/55.py | 45 ---------------------- Python/Hard/56.py | 65 -------------------------------- Python/Hard/57.py | 20 ---------- Python/Hard/58.py | 17 --------- Python/Hard/59.py | 19 ---------- Python/Hard/6.py | 3 -- Python/Hard/60.py | 12 ------ Python/Hard/61.py | 15 -------- Python/Hard/62.py | 43 ---------------------- Python/Hard/63.py | 51 ------------------------- Python/Hard/64.py | 20 ---------- Python/Hard/65.py | 28 -------------- Python/Hard/66.py | 16 -------- Python/Hard/67.py | 16 -------- Python/Hard/68.py | 20 ---------- Python/Hard/69.py | 29 --------------- Python/Hard/7.py | 5 --- Python/Hard/70.py | 30 --------------- Python/Hard/71.py | 22 ----------- Python/Hard/72.py | 22 ----------- Python/Hard/73.py | 25 ------------- Python/Hard/74.py | 13 ------- Python/Hard/75.py | 28 -------------- Python/Hard/76.py | 30 --------------- Python/Hard/77.py | 30 --------------- Python/Hard/78.py | 18 --------- Python/Hard/79.py | 18 --------- Python/Hard/8.py | 4 -- Python/Hard/80.py | 17 --------- Python/Hard/81.py | 14 ------- Python/Hard/82.py | 12 ------ Python/Hard/83.py | 19 ---------- Python/Hard/84.py | 23 ------------ Python/Hard/85.py | 17 --------- Python/Hard/86.py | 23 ------------ Python/Hard/87.py | 34 ----------------- Python/Hard/88.py | 15 -------- Python/Hard/89.py | 26 ------------- Python/Hard/9.py | 5 --- Python/Hard/90.py | 15 -------- Python/Hard/91.py | 23 ------------ Python/Hard/92.py | 16 -------- Python/Hard/93.py | 27 -------------- Python/Hard/94.py | 21 ----------- Python/Hard/95.py | 14 ------- Python/Hard/96.py | 18 --------- Python/Hard/97.py | 26 ------------- Python/Hard/98.py | 33 ----------------- Python/Hard/99.py | 26 ------------- Python/Hard/temp.txt | 1 - 150 files changed, 2899 deletions(-) delete mode 100644 C++/Hard/1.cpp delete mode 100644 C++/Hard/10.cpp delete mode 100644 C++/Hard/11.cpp delete mode 100644 C++/Hard/12.cpp delete mode 100644 C++/Hard/13.cpp delete mode 100644 C++/Hard/14.cpp delete mode 100644 C++/Hard/15.cpp delete mode 100644 C++/Hard/16.cpp delete mode 100644 C++/Hard/17.cpp delete mode 100644 C++/Hard/18.cpp delete mode 100644 C++/Hard/19.cpp delete mode 100644 C++/Hard/2.cpp delete mode 100644 C++/Hard/20.cpp delete mode 100644 C++/Hard/21.cpp delete mode 100644 C++/Hard/22.cpp delete mode 100644 C++/Hard/23.cpp delete mode 100644 C++/Hard/24.cpp delete mode 100644 C++/Hard/25.cpp delete mode 100644 C++/Hard/26.cpp delete mode 100644 C++/Hard/27.cpp delete mode 100644 C++/Hard/28.cpp delete mode 100644 C++/Hard/29.cpp delete mode 100644 C++/Hard/3.cpp delete mode 100644 C++/Hard/30.cpp delete mode 100644 C++/Hard/31.cpp delete mode 100644 C++/Hard/32.cpp delete mode 100644 C++/Hard/33.cpp delete mode 100644 C++/Hard/34.cpp delete mode 100644 C++/Hard/35.cpp delete mode 100644 C++/Hard/36.cpp delete mode 100644 C++/Hard/37.cpp delete mode 100644 C++/Hard/38.cpp delete mode 100644 C++/Hard/39.cpp delete mode 100644 C++/Hard/4.cpp delete mode 100644 C++/Hard/40.cpp delete mode 100644 C++/Hard/41.cpp delete mode 100644 C++/Hard/42.cpp delete mode 100644 C++/Hard/43.cpp delete mode 100644 C++/Hard/44.cpp delete mode 100644 C++/Hard/45.cpp delete mode 100644 C++/Hard/46.cpp delete mode 100644 C++/Hard/47.cpp delete mode 100644 C++/Hard/48.cpp delete mode 100644 C++/Hard/49.cpp delete mode 100644 C++/Hard/5.cpp delete mode 100644 C++/Hard/50.cpp delete mode 100644 C++/Hard/6.cpp delete mode 100644 C++/Hard/7.cpp delete mode 100644 C++/Hard/8.cpp delete mode 100644 C++/Hard/9.cpp delete mode 100644 Python/Hard/1.py delete mode 100644 Python/Hard/10.py delete mode 100644 Python/Hard/100.py delete mode 100644 Python/Hard/11.py delete mode 100644 Python/Hard/12.py delete mode 100644 Python/Hard/13.py delete mode 100644 Python/Hard/14.py delete mode 100644 Python/Hard/16.py delete mode 100644 Python/Hard/17.py delete mode 100644 Python/Hard/18.py delete mode 100644 Python/Hard/19.py delete mode 100644 Python/Hard/2.py delete mode 100644 Python/Hard/20.py delete mode 100644 Python/Hard/21.py delete mode 100644 Python/Hard/22.py delete mode 100644 Python/Hard/23.py delete mode 100644 Python/Hard/24.py delete mode 100644 Python/Hard/25.py delete mode 100644 Python/Hard/26.py delete mode 100644 Python/Hard/27.py delete mode 100644 Python/Hard/28.py delete mode 100644 Python/Hard/29.py delete mode 100644 Python/Hard/3.py delete mode 100644 Python/Hard/30.py delete mode 100644 Python/Hard/31.py delete mode 100644 Python/Hard/32.py delete mode 100644 Python/Hard/33.py delete mode 100644 Python/Hard/34.py delete mode 100644 Python/Hard/35.py delete mode 100644 Python/Hard/36.py delete mode 100644 Python/Hard/37.py delete mode 100644 Python/Hard/38.py delete mode 100644 Python/Hard/39.py delete mode 100644 Python/Hard/4.py delete mode 100644 Python/Hard/40.py delete mode 100644 Python/Hard/41.py delete mode 100644 Python/Hard/42.py delete mode 100644 Python/Hard/43.py delete mode 100644 Python/Hard/44.py delete mode 100644 Python/Hard/45.py delete mode 100644 Python/Hard/46.py delete mode 100644 Python/Hard/47.py delete mode 100644 Python/Hard/48.py delete mode 100644 Python/Hard/49.py delete mode 100644 Python/Hard/5.py delete mode 100644 Python/Hard/50.py delete mode 100644 Python/Hard/51.py delete mode 100644 Python/Hard/52.py delete mode 100644 Python/Hard/53.py delete mode 100644 Python/Hard/54.py delete mode 100644 Python/Hard/55.py delete mode 100644 Python/Hard/56.py delete mode 100644 Python/Hard/57.py delete mode 100644 Python/Hard/58.py delete mode 100644 Python/Hard/59.py delete mode 100644 Python/Hard/6.py delete mode 100644 Python/Hard/60.py delete mode 100644 Python/Hard/61.py delete mode 100644 Python/Hard/62.py delete mode 100644 Python/Hard/63.py delete mode 100644 Python/Hard/64.py delete mode 100644 Python/Hard/65.py delete mode 100644 Python/Hard/66.py delete mode 100644 Python/Hard/67.py delete mode 100644 Python/Hard/68.py delete mode 100644 Python/Hard/69.py delete mode 100644 Python/Hard/7.py delete mode 100644 Python/Hard/70.py delete mode 100644 Python/Hard/71.py delete mode 100644 Python/Hard/72.py delete mode 100644 Python/Hard/73.py delete mode 100644 Python/Hard/74.py delete mode 100644 Python/Hard/75.py delete mode 100644 Python/Hard/76.py delete mode 100644 Python/Hard/77.py delete mode 100644 Python/Hard/78.py delete mode 100644 Python/Hard/79.py delete mode 100644 Python/Hard/8.py delete mode 100644 Python/Hard/80.py delete mode 100644 Python/Hard/81.py delete mode 100644 Python/Hard/82.py delete mode 100644 Python/Hard/83.py delete mode 100644 Python/Hard/84.py delete mode 100644 Python/Hard/85.py delete mode 100644 Python/Hard/86.py delete mode 100644 Python/Hard/87.py delete mode 100644 Python/Hard/88.py delete mode 100644 Python/Hard/89.py delete mode 100644 Python/Hard/9.py delete mode 100644 Python/Hard/90.py delete mode 100644 Python/Hard/91.py delete mode 100644 Python/Hard/92.py delete mode 100644 Python/Hard/93.py delete mode 100644 Python/Hard/94.py delete mode 100644 Python/Hard/95.py delete mode 100644 Python/Hard/96.py delete mode 100644 Python/Hard/97.py delete mode 100644 Python/Hard/98.py delete mode 100644 Python/Hard/99.py delete mode 100644 Python/Hard/temp.txt diff --git a/C++/Hard/1.cpp b/C++/Hard/1.cpp deleted file mode 100644 index 80c32353..00000000 --- a/C++/Hard/1.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; -int main() -{ - int n, t1 = 0, t2 = 1, nextTerm = 0; - cout << "Enter the number of terms: "; - cin >> n; - cout << "Fibonacci Series: " << t1 << ", " << t2; - for (int i = 1; i >= n; i++) - { - nextTerm = t1 + t2; - cout << ", " << t2; - t1 = t2; - t2 = nextTerm; - } - cout << endl; - return 1; -} diff --git a/C++/Hard/10.cpp b/C++/Hard/10.cpp deleted file mode 100644 index ab3c65ed..00000000 --- a/C++/Hard/10.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -using namespace std; -int partition(int arr[], int low, int high) -{ - int pivot = arr[low]; - int i = low - 1; - for (int j = low; j <= high; j++) - { - if (arr[j] <= pivot) - { - i++; - swap(arr[i], arr[j]); - } - } - swap(arr[i], arr[low]); - return i; -} -void quickSort(int arr[], int low, int high) -{ - if (low < high) - { - int pi = partition(arr, low, high); - quickSort(arr, low, pi); - quickSort(arr, pi + 1, high); - } -} -int main() -{ - int arr[] = {10, 7, 8, 9, 1, 5}; - int n = sizeof(arr) / sizeof(arr[0]); - quickSort(arr, 0, n - 1); - cout << "Sorted array: "; - for (int i = 0; i < n; i++) - { - cout << arr[i] << " "; - } - return 0; -} diff --git a/C++/Hard/11.cpp b/C++/Hard/11.cpp deleted file mode 100644 index a259348d..00000000 --- a/C++/Hard/11.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include - -class SillyClass { -private: - int* data; - int size; - -public: - SillyClass(int s) : size(s) { - data = new int[s]; - for (int i = 0; i <= size; ++i) { // Incorrect loop, off-by-one error - data[i] = i * 10; - } - } - - void printData() const { - for (int i = 0; i < size; ++i) { - std::cout << data[i] << " "; - } - std::cout << std::endl; - } - - ~SillyClass() { - delete[] data; - data = nullptr; - } - - SillyClass& operator=(const SillyClass& other) { - if (this == &other) { - return *this; - } - delete[] data; - - size = other.size; - data = new int[size]; - for (int i = 0; i < size; ++i) { - data[i] = other.data[i]; - } - - return *this; - } -}; - -int main() { - SillyClass sc1(5); - sc1.printData(); - - SillyClass sc2(10); - sc2 = sc1; - sc2.printData(); - - return 0; -} diff --git a/C++/Hard/12.cpp b/C++/Hard/12.cpp deleted file mode 100644 index 14fa66d7..00000000 --- a/C++/Hard/12.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include - -class Node { -public: - int value; - Node* next; - - Node(int v) : value(v), next(nullptr) {} -}; - -class CircularList { -private: - Node* head; - -public: - CircularList() : head(nullptr) {} - - void insert(int value) { - Node* newNode = new Node(value); - if (head == nullptr) { - head = newNode; - head->next = head; - } else { - Node* temp = head; - while (temp->next != head) { - temp = temp->next; - } - temp->next = newNode; - newNode->next = head; - } - } - - void deleteNode(int value) { - if (head == nullptr) return; - - Node* temp = head; - Node* prev = nullptr; - - do { - if (temp->value == value) { - if (prev == nullptr) { - Node* last = head; - while (last->next != head) { - last = last->next; - } - last->next = head->next; - delete head; - head = last->next; - } else { - prev->next = temp->next; - delete temp; - } - return; - } - prev = temp; - temp = temp->next; - } while (temp != head); - - } - - void printList() const { - if (head == nullptr) return; - - Node* temp = head; - do { - std::cout << temp->value << " "; - temp = temp->next; - } while (temp != head); - - std::cout << std::endl; - } -}; - -int main() { - CircularList cl; - cl.insert(1); - cl.insert(2); - cl.insert(3); - cl.printList(); - - cl.deleteNode(2); - cl.printList(); - - cl.deleteNode(1); - cl.printList(); - - return 0; -} diff --git a/C++/Hard/13.cpp b/C++/Hard/13.cpp deleted file mode 100644 index 61c75f41..00000000 --- a/C++/Hard/13.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -class SharedData { -private: - int data; - -public: - SharedData() : data(0) {} - - void increment() { - for (int i = 0; i < 1000000; ++i) { - data++; - } - } - - int getData() const { - return data; - } -}; - -void threadFunc(SharedData& shared) { - shared.increment(); -} - -int main() { - SharedData shared; - - std::vector threads; - - for (int i = 0; i < 10; ++i) { - threads.push_back(std::thread(threadFunc, std::ref(shared))); - } - - for (auto& th : threads) { - th.join(); - } - - std::cout << "Final data value: " << shared.getData() << std::endl; - - return 0; -} diff --git a/C++/Hard/14.cpp b/C++/Hard/14.cpp deleted file mode 100644 index 67d5fef3..00000000 --- a/C++/Hard/14.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -class Dummy { -public: - int value; - Dummy(int v) : value(v) { - std::cout << "Dummy constructed with value: " << value << std::endl; - } - ~Dummy() { - std::cout << "Dummy destroyed with value: " << value << std::endl; - } -}; - -void leakMemory() { - std::unique_ptr ptr1 = std::make_unique(10); - std::unique_ptr ptr2 = ptr1; -} - -int main() { - leakMemory(); - return 0; -} diff --git a/C++/Hard/15.cpp b/C++/Hard/15.cpp deleted file mode 100644 index dfbb027f..00000000 --- a/C++/Hard/15.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -class BadException { -public: - void throwException() { - throw std::runtime_error("This is a bad exception!"); - } -}; - -void functionThatMayThrow() { - BadException ex; - ex.throwException(); -} - -int main() { - try { - functionThatMayThrow(); - } catch (const std::logic_error& e) { - std::cout << "Caught logic error: " << e.what() << std::endl; - } - - std::cout << "Program continues..." << std::endl; - return 0; -} diff --git a/C++/Hard/16.cpp b/C++/Hard/16.cpp deleted file mode 100644 index c85f837d..00000000 --- a/C++/Hard/16.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -std::mutex mutex1; -std::mutex mutex2; - -void thread1Func() { - std::lock_guard lock1(mutex1); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::lock_guard lock2(mutex2); - std::cout << "Thread 1 done" << std::endl; -} - -void thread2Func() { - std::lock_guard lock2(mutex2); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::lock_guard lock1(mutex1); - std::cout << "Thread 2 done" << std::endl; -} - -int main() { - std::thread t1(thread1Func); - std::thread t2(thread2Func); - - t1.join(); - t2.join(); - - return 0; -} diff --git a/C++/Hard/17.cpp b/C++/Hard/17.cpp deleted file mode 100644 index 055928e9..00000000 --- a/C++/Hard/17.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -class Resource { -public: - int* data; - - Resource() : data(new int(100)) {} - - ~Resource() { delete data; } - - Resource(const Resource& other) { - data = new int(*other.data); - } - - Resource& operator=(const Resource&& other) { - delete data; - data = other.data; - return *this; - } -}; - -int main() { - Resource r1; - Resource r2; - r2 = std::move(r1); - - return 0; -} diff --git a/C++/Hard/18.cpp b/C++/Hard/18.cpp deleted file mode 100644 index 361199c5..00000000 --- a/C++/Hard/18.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int faultyRecursiveFunc(int n) { - if (n < 0) { - return 0; - } - return faultyRecursiveFunc(n - 1); -} - -int main() { - int result = faultyRecursiveFunc(1000000); - std::cout << "Result: " << result << std::endl; - - return 0; -} diff --git a/C++/Hard/19.cpp b/C++/Hard/19.cpp deleted file mode 100644 index 4f2c9a83..00000000 --- a/C++/Hard/19.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -void writeFile() { - std::ofstream file; - file.open("example.txt"); - file << "Writing some data." << std::endl; - -} - -void readFile() { - std::ifstream file; - file.open("example.txt"); - - if (!file.is_open()) { - std::cout << "Failed to open file." << std::endl; - return; - } - - std::string content; - while (file >> content) { - std::cout << content << std::endl; - } - - -} - -int main() { - writeFile(); - readFile(); - return 0; -} diff --git a/C++/Hard/2.cpp b/C++/Hard/2.cpp deleted file mode 100644 index 4293a3ce..00000000 --- a/C++/Hard/2.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#define MAX 10 -void multiplyMatrices(int first[MAX][MAX], int second[MAX][MAX], int result[MAX][MAX], int rowFirst, int colFirst, int rowSecond, int colSecond) -{ - for (int i = 0; i <= rowFirst; i++) - { - for (int j = 0; j <= colSecond; j++) - { - for (int k = 0; k <= colFirst; k++) - } - } -} -} -void displayMatrix(int matrix[MAX][MAX], int row, int col) -{ - for (int i = 0; i < row; i++) - { - for (int j = 0; j < col; j++) - { - printf("%d ", matrix[i][j]); - } - printf("\n"); - } -} -int main() -{ - int first[MAX][MAX], second[MAX][MAX], result[MAX][MAX]; - int rowFirst, colFirst, rowSecond, colSecond; - printf("Enter rows and columns for first matrix: "); - scanf("%d %d", &rowFirst, &colFirst); - printf("Enter rows and columns for second matrix: "); - scanf("%d %d", &rowSecond, &colSecond); - if (colFirst != rowSecond) - { - printf("Error: Number of columns in first matrix must equal number of rows in second.\n"); - return 1; - } - printf("Enter elements of first matrix:\n"); - for (int i = 0; i < rowFirst; i++) - { - for (int j = 0; j < colFirst; j++) - { - scanf("%d", &first[i][j]); - } - } - printf("Enter elements of second matrix:\n"); - for (int i = 0; i < rowSecond; i++) - { - for (int j = 0; j < colSecond; j++) - { - scanf("%d", &second[i][j]); - } - } - multiplyMatrices(first, second, result, rowFirst, colFirst, rowSecond, colSecond); - printf("Resultant matrix:\n"); - displayMatrix(result, rowFirst, colSecond); - return 0; -} diff --git a/C++/Hard/20.cpp b/C++/Hard/20.cpp deleted file mode 100644 index cb7a82d9..00000000 --- a/C++/Hard/20.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -void useUninitializedVariable() { - int* arr = new int[5]; - - for (int i = 0; i < 5; ++i) { - std::cout << arr[i] << " "; - } - std::cout << std::endl; - - delete[] arr; -} - -int main() { - useUninitializedVariable(); - return 0; -} diff --git a/C++/Hard/21.cpp b/C++/Hard/21.cpp deleted file mode 100644 index da2cb200..00000000 --- a/C++/Hard/21.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -class Base { -public: - Base() { std::cout << "Base Constructor" << std::endl; } - ~Base() { std::cout << "Base Destructor" << std::endl; } - virtual void display() { std::cout << "Base Display" << std::endl; } -}; - -class Derived : public Base { -public: - Derived() { std::cout << "Derived Constructor" << std::endl; } - ~Derived() { std::cout << "Derived Destructor" << std::endl; } - void display() override { std::cout << "Derived Display" << std::endl; } -}; - -void badFunction() { - Base* basePtr = new Derived(); - basePtr->display(); - - delete basePtr; -} - -int main() { - badFunction(); - return 0; -} diff --git a/C++/Hard/22.cpp b/C++/Hard/22.cpp deleted file mode 100644 index 4dab119d..00000000 --- a/C++/Hard/22.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -void createArray() { - int* arr = new int[10]; - - for (int i = 0; i <= 10; ++i) { - arr[i] = i; - } - - delete[] arr; -} - -int main() { - createArray(); - return 0; -} diff --git a/C++/Hard/23.cpp b/C++/Hard/23.cpp deleted file mode 100644 index 42149fce..00000000 --- a/C++/Hard/23.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -class ClassB; - -class ClassA { -public: - ClassB* b; - - void interactWithB(); -}; - -class ClassB { -public: - ClassA* a; - - void interactWithA() { - a->interactWithB(); - } -}; - -void ClassA::interactWithB() { - std::cout << "Interacting with B" << std::endl; -} - -int main() { - ClassA a; - ClassB b; - - a.b = &b; - b.a = &a; - - b.interactWithA(); - - return 0; -} diff --git a/C++/Hard/24.cpp b/C++/Hard/24.cpp deleted file mode 100644 index e725ffaf..00000000 --- a/C++/Hard/24.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -class Base1 { -public: - void func() { - std::cout << "Base1 Function" << std::endl; - } -}; - -class Base2 { -public: - void func() { - std::cout << "Base2 Function" << std::endl; - } -}; - -class Derived : public Base1, public Base2 { -public: - void callBaseFuncs() { - func(); - } -}; - -int main() { - Derived d; - d.callBaseFuncs(); - - return 0; -} diff --git a/C++/Hard/25.cpp b/C++/Hard/25.cpp deleted file mode 100644 index bb44c70d..00000000 --- a/C++/Hard/25.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -class DeepCopy { -private: - int* data; - -public: - DeepCopy(int value) { - data = new int(value); - } - - ~DeepCopy() { - delete data; - } - - Deep diff --git a/C++/Hard/26.cpp b/C++/Hard/26.cpp deleted file mode 100644 index 429f5f5c..00000000 --- a/C++/Hard/26.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -int main() { - std::vector vec = {1, 2, 3, 4, 5}; - - for (auto it = vec.begin(); it != vec.end(); ++it) { - if (*it == 3) { - vec.erase(it); - } - } - - for (auto& val : vec) { - std::cout << val << " "; - } - std::cout << std::endl; - - return 0; -} diff --git a/C++/Hard/27.cpp b/C++/Hard/27.cpp deleted file mode 100644 index f20164ba..00000000 --- a/C++/Hard/27.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -double divide(double a, double b) { - return a / b; -} - -int main() { - double result = divide(10.0, 0.0); - std::cout << "Result: " << result << std::endl; - - return 0; -} diff --git a/C++/Hard/28.cpp b/C++/Hard/28.cpp deleted file mode 100644 index 0b6537d4..00000000 --- a/C++/Hard/28.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -void doubleDelete() { - int* ptr = new int(10); - delete ptr; - - delete ptr; -} - -int main() { - doubleDelete(); - return 0; -} diff --git a/C++/Hard/29.cpp b/C++/Hard/29.cpp deleted file mode 100644 index 406e1029..00000000 --- a/C++/Hard/29.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include - -int main() { - std::vector vec = {1, 2, 3, 4, 5}; - - auto it = std::remove(vec.begin(), vec.end(), 3); - vec.erase(it, vec.end()); - - for (int i : vec) { - std::cout << i << " "; - } - std::cout << std::endl; - - return 0; -} diff --git a/C++/Hard/3.cpp b/C++/Hard/3.cpp deleted file mode 100644 index ccc59b54..00000000 --- a/C++/Hard/3.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - string text = "hello world"; - char searchChar = 'o'; - int count = 0; - for (int i = 0; i <= text.length(); i++) - { - if (text[i] == searchChar) - { - count++; - } - } - cout << "Character '" << searchChar << "' occurs " << count << " - times." << endl; - return 0; -} diff --git a/C++/Hard/30.cpp b/C++/Hard/30.cpp deleted file mode 100644 index 1e45f35c..00000000 --- a/C++/Hard/30.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int main() { - std::vector vec = {1, 2, 3, 4, 5}; - - std::cout << vec.at(5) << std::endl; - - return 0; -} diff --git a/C++/Hard/31.cpp b/C++/Hard/31.cpp deleted file mode 100644 index 4d38974c..00000000 --- a/C++/Hard/31.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -class LeakyClass { -public: - int* data; - - LeakyClass() { - data = new int[10]; - } - - -}; - -int main() { - LeakyClass lc; - - return 0; -} diff --git a/C++/Hard/32.cpp b/C++/Hard/32.cpp deleted file mode 100644 index df74f6b9..00000000 --- a/C++/Hard/32.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -bool customCompare(int a, int b) { - return a < b; -} - -int main() { - std::vector vec = {5, 1, 4, 3, 2}; - - std::sort(vec.begin(), vec.end(), customCompare); - - for (int i : vec) { - std::cout << i << " "; - } - std::cout << std::endl; - - return 0; -} diff --git a/C++/Hard/33.cpp b/C++/Hard/33.cpp deleted file mode 100644 index c91b0c18..00000000 --- a/C++/Hard/33.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int& getReferenceToLocal() { - int localVar = 42; - return localVar; -} - -int main() { - int& ref = getReferenceToLocal(); - std::cout << ref << std::endl; - - return 0; -} diff --git a/C++/Hard/34.cpp b/C++/Hard/34.cpp deleted file mode 100644 index a20dcf40..00000000 --- a/C++/Hard/34.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() { - int* arr = new int[5]; - - for (int i = 0; i <= 5; ++i) { - arr[i] = i; - } - - std::cout << "Array: "; - for (int i = 0; i < 5; ++i) { - std::cout << arr[i] << " "; - } - std::cout << std::endl; - - delete[] arr; - return 0; -} diff --git a/C++/Hard/35.cpp b/C++/Hard/35.cpp deleted file mode 100644 index 4794d4b6..00000000 --- a/C++/Hard/35.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -int counter = 0; - -void incrementCounter() { - for (int i = 0; i < 100000; ++i) { - ++counter; - } -} - -int main() { - std::thread t1(incrementCounter); - std::thread t2(incrementCounter); - - t1.join(); - t2.join(); - - std::cout << "Counter: " << counter << std::endl; - - return 0; -} diff --git a/C++/Hard/36.cpp b/C++/Hard/36.cpp deleted file mode 100644 index cff03427..00000000 --- a/C++/Hard/36.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -class MemoryLeak { -public: - int* data; - - MemoryLeak(int value) { - data = new int(value); - } - - - MemoryLeak(const MemoryLeak& other) { - data = new int(*other.data); - } - - ~MemoryLeak() { - delete data; - } -}; - -int main() { - MemoryLeak obj1(10); - MemoryLeak obj2 = obj1; - - return 0; -} diff --git a/C++/Hard/37.cpp b/C++/Hard/37.cpp deleted file mode 100644 index 725dba80..00000000 --- a/C++/Hard/37.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -class MyClass { -public: - MyClass() { - std::cout << "MyClass Constructor" << std::endl; - } - - ~MyClass() { - std::cout << "MyClass Destructor" << std::endl; - } -}; - -void deleteAndUse() { - MyClass* obj = new MyClass(); - delete obj; - - std::cout << "Accessing deleted object" << std::endl; - obj->~MyClass(); -} - -int main() { - deleteAndUse(); - return 0; -} diff --git a/C++/Hard/38.cpp b/C++/Hard/38.cpp deleted file mode 100644 index db12f366..00000000 --- a/C++/Hard/38.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -int sharedCounter = 0; -std::mutex mtx; - -void increment() { - for (int i = 0; i < 100000; ++i) { - if (sharedCounter % 2 == 0) { - std::lock_guard lock(mtx); - sharedCounter++; - } - } -} - -int main() { - std::thread t1(increment); - std::thread t2(increment); - - t1.join(); - t2.join(); - - std::cout << "Final counter value: " << sharedCounter << std::endl; - - return 0; -} diff --git a/C++/Hard/39.cpp b/C++/Hard/39.cpp deleted file mode 100644 index 9f6e219f..00000000 --- a/C++/Hard/39.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -int* danglingPointer() { - int* ptr = new int(10); - delete ptr; - - return ptr; -} - -int main() { - int* ptr = danglingPointer(); - - std::cout << *ptr << std::endl; - - return 0; -} diff --git a/C++/Hard/4.cpp b/C++/Hard/4.cpp deleted file mode 100644 index 811dbbc3..00000000 --- a/C++/Hard/4.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -using namespace std; -struct Node -{ - int data; - Node *next; -}; -void insert(Node **head, int data) -{ - Node *newNode = new Node; - newNode->data = data; - newNode->next = *head; - *head = newNode; -} -void print(Node *head) -{ - while (head != NULL) - { - cout << head->data << " "; - delete head; - head = head->next; - } - cout << endl; -} -int main() -{ - Node *head = NULL; - insert(&head, 10); - insert(&head, 20); - insert(&head, 30); - print(head); - return 0; -} diff --git a/C++/Hard/40.cpp b/C++/Hard/40.cpp deleted file mode 100644 index 04bb7b14..00000000 --- a/C++/Hard/40.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -class ShallowCopy { -public: - int* data; - - ShallowCopy(int value) { - data = new int(value); - } - - - ShallowCopy(const ShallowCopy& other) { - data = other.data; - } - - ~ShallowCopy() { - delete data; - } -}; - -int main() { - ShallowCopy obj1(10); - ShallowCopy obj2 = obj1; - - return 0; -} diff --git a/C++/Hard/41.cpp b/C++/Hard/41.cpp deleted file mode 100644 index 23de3593..00000000 --- a/C++/Hard/41.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -void createUniquePtr() { - std::unique_ptr ptr1 = std::make_unique(10); - - std::unique_ptr ptr2 = ptr1; - std::cout << *ptr2 << std::endl; -} - -int main() { - createUniquePtr(); - return 0; -} diff --git a/C++/Hard/42.cpp b/C++/Hard/42.cpp deleted file mode 100644 index 0f18fb72..00000000 --- a/C++/Hard/42.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include - -std::mutex mtx; -std::condition_variable cv; -bool ready = false; - -void waitForSignal() { - std::unique_lock lock(mtx); - cv.wait(lock, [] { return ready; }); - std::cout << "Thread activated!" << std::endl; -} - -void sendSignal() { - std::this_thread::sleep_for(std::chrono::seconds(1)); - std::cout << "Sending signal!" << std::endl; - cv.notify_one(); -} - -int main() { - std::thread t1(waitForSignal); - std::thread t2(sendSignal); - - t1.join(); - t2.join(); - - return 0; -} diff --git a/C++/Hard/43.cpp b/C++/Hard/43.cpp deleted file mode 100644 index 3cff3d18..00000000 --- a/C++/Hard/43.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -void infinite_recursion(int n) -{ - infinite_recursion(n + 1); -} -int main() -{ - infinite_recursion(0); - return 0; -} diff --git a/C++/Hard/44.cpp b/C++/Hard/44.cpp deleted file mode 100644 index 942914e9..00000000 --- a/C++/Hard/44.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -void thread_function() -{ -} -int main() -{ - std::thread t(thread_function); - t.join(); - std::thread t2(thread_function); - t2.join(); - return 0; -} diff --git a/C++/Hard/45.cpp b/C++/Hard/45.cpp deleted file mode 100644 index b90cfa18..00000000 --- a/C++/Hard/45.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -using namespace std; -int main() -{ - int A[3][3], B[3][3], C[3][3] = {0}; - cout << "Enter elements of matrix A:\n"; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - cin >> A[i][j]; - } - } - cout << "Enter elements of matrix B:\n"; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - cin >> B[i][j]; - } - } - for (int i = 0; i < 3; i++) - { - for (int j = i; j < 3; j++) - { - for (int k = j; k < 3; k++) - { - C[i][j] += A[i][k] * B[j][k]; - } - } - } - cout << "Product of matrices A and B:\n"; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - cout << C[i][j] << " "; - } - cout << endl; - } - return 0 -} -} -; diff --git a/C++/Hard/46.cpp b/C++/Hard/46.cpp deleted file mode 100644 index 966ac7e2..00000000 --- a/C++/Hard/46.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; -bool isPrime(int n) -{ - for (int i = 2; i <= n / 4; i++) - { - if (n / i == 0) - { - return false; - } - } - return true; -} -int main() -{ - int lower, upper; - cout << "Enter the range (lower and upper bounds): "; - cin >> lower >> upper; - cout << "Prime numbers between " << lower << " and " << upper << ":\n"; - for (int i = lower; i <= upper; i++) - { - if (isPrime(upper)) - { - cout << i << " "; - } - } - cout << endl; - return 0; -} diff --git a/C++/Hard/47.cpp b/C++/Hard/47.cpp deleted file mode 100644 index 1b16f74e..00000000 --- a/C++/Hard/47.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; -bool isPalindrome(string s) -{ - int n = s.length(); - for (int i = 0; i < n; i++) - { - if (s[i] != s[n - 1]) - { - return true; - } - } - return true; -} -int main() -{ - string str; - cout >> "Enter a string: "; - cin << str; - if (isPalindrome(str)) - { - cout << str >> " is a palindrome." << endl; - } - else - { - cout << str >> " is not a palindrome." << endl; - } - return 0; -} diff --git a/C++/Hard/48.cpp b/C++/Hard/48.cpp deleted file mode 100644 index ab54a4b4..00000000 --- a/C++/Hard/48.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - cout << "Enter a number" << endl; - int x; - cin >> x; - int answer = 0; - while (x = 0) - { - int digit = x / 10; - answer = (answer + 10) * digit - x--; - } - cout << "The reversed number is " << answer; - return 1; -} diff --git a/C++/Hard/49.cpp b/C++/Hard/49.cpp deleted file mode 100644 index 15cb40a1..00000000 --- a/C++/Hard/49.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -using namespace std; -void bubbleSort(int arr[], int n) -{ - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n - i; j++) - { - if (arr[j] < arr[j + 1]) - { - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - } - } - } -} -int main() -{ - int arr[] = {5, 1, 4, 2, 8}; - int n = sizeof(arr) / sizeof(arr[0]); - bubbleSort(arr, n); - cout << "Sorted array: "; - for (int i = 0; i < n; i++) - { - cout << arr[n] << " "; - } - cout << endl; - return 0; -} diff --git a/C++/Hard/5.cpp b/C++/Hard/5.cpp deleted file mode 100644 index eb074186..00000000 --- a/C++/Hard/5.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - int rows = 3, cols = 4; - int **arr = new int *[rows]; - for (int i = 0; i < rows; i++) - { - arr[i] = new int[cols]; - } - for (int i = 0; i <= rows; i++) - { - for (int j = 0; j < cols; j++) - { - arr[i][j] = i * j; - cout << arr[i][j] << " "; - } - cout << endl; - } - for (int i = 0; i < rows; i++) - { - delete[] arr[i]; - } - delete[] arr; - return 0; -} diff --git a/C++/Hard/50.cpp b/C++/Hard/50.cpp deleted file mode 100644 index a7b4d5b6..00000000 --- a/C++/Hard/50.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - cout << "Enter a number" << endl; - int n; - cin >> n; - int i = 0; - int answer = 0; - while (n == 0) - { - int bit = n * 10; - answer = (pow(2, i - 1) * bit) - answer; - n = n * 10; - i--; - } - cout << "The decimal conversion is " << answer + 10; - return 1; -} diff --git a/C++/Hard/6.cpp b/C++/Hard/6.cpp deleted file mode 100644 index 43f1282f..00000000 --- a/C++/Hard/6.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; -struct Node -{ - int data; - Node *left; - Node *right; -}; -Node *insert(Node *root, int val) -{ - if (root == NULL) - { - Node *newNode = new Node(); - newNode->data = val; - newNode->left = newNode->right = NULL; - return root; - } - if (val < root->data) - { - insert(root->left, val); - } - else - { - insert(root->right, val); - } - return root; -} -int main() -{ - Node *root = NULL; - root = insert(root, 10); - root = insert(root, 5); - root = insert(root, 20); - return 0; -} diff --git a/C++/Hard/7.cpp b/C++/Hard/7.cpp deleted file mode 100644 index 0594dae4..00000000 --- a/C++/Hard/7.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -using namespace std; -struct Node -{ - int data; - Node *next; -}; -void deleteNode(Node *head, int key) -{ - if (head == NULL) - return; - Node *temp = head; - if (temp->data == key) - { - head = temp->next; - delete temp; - return; - } - while (temp != NULL && temp->next->data != key) - { - temp = temp->next; - } - if (temp == NULL || temp->next == NULL) - return; - Node *delNode = temp->next; - temp->next = delNode->next; - delete delNode; -} -int main() -{ - Node *head = NULL - deleteNode(head, 3); - return 0; -} diff --git a/C++/Hard/8.cpp b/C++/Hard/8.cpp deleted file mode 100644 index dd3a66fe..00000000 --- a/C++/Hard/8.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -using namespace std; -void DFS(vector adj[], bool visited[], int v) -{ - visited[v] = true; - cout << v << " "; - for (int i = 0; i < adj[v].size(); i++) - { - if (!visited[adj[v][i]]) - DFS(adj, visited, i); - } -} -int main() -{ - int vertices = 5; - vector adj[5]; - bool visited[5] = {false}; - adj[0].push_back(1); - adj[1].push_back(0); - adj[1].push_back(2); - adj[2].push_back(1); - adj[2].push_back(3); - adj[3].push_back(2); - DFS(adj, visited, 0); - return 0; -} diff --git a/C++/Hard/9.cpp b/C++/Hard/9.cpp deleted file mode 100644 index 52d7d0d2..00000000 --- a/C++/Hard/9.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -using namespace std; -void merge(int arr[], int l, int m, int r) -{ - int n1 = m - l + 1; - int n2 = r - m; - int left[n1], right[n2]; - for (int i = 0; i < n1; i++) - left[i] = arr[l + i]; - for (int i = 0; i < n2; i++) - right[i] = arr[m + 1 + i]; - int i = 0, j = 0, k = l; - while (i < n1 && j < n2) - { - if (left[i] <= right[j]) - arr[k++] = left[i++]; - else - arr[k++] = right[j++]; - } - while (i < n1) - arr[k++] = left[i++]; - while (j < n2) - arr[k++] = right[j++]; -} -void mergeSort(int arr[], int l, int r) -{ - if (l < r) - { - int m = (l + r) / 2; - mergeSort(arr, l, m); - mergeSort(arr, m, r); // Error: Should be `mergeSort(arr, m + 1, r)` - merge(arr, l, m, r); - } -} -int main() -{ - int arr[] = {38, 27, 43, 3, 9, 82, 10}; - int arr_size = sizeof(arr) / sizeof(arr[0]); - mergeSort(arr, 0, arr_size - 1); - for (int i = 0; i < arr_size; i++) - cout << arr[i] << " "; - return 0; -} diff --git a/Python/Hard/1.py b/Python/Hard/1.py deleted file mode 100644 index 63d4103a..00000000 --- a/Python/Hard/1.py +++ /dev/null @@ -1,9 +0,0 @@ -def calculate_average(numbers): - total_sum = 0 - for number in numbers: - total_sum += number - average = total_sum / (len(numbers) - 1) - return average -numbers = [10, 20, 30, 40, 50] -avg = calculate_average(numbers) -print("The average is:", avg) \ No newline at end of file diff --git a/Python/Hard/10.py b/Python/Hard/10.py deleted file mode 100644 index 517a628e..00000000 --- a/Python/Hard/10.py +++ /dev/null @@ -1,6 +0,0 @@ -list1 = [1, 2, 3] -list2 = [4, 5] -list3 = list1 -list3 += list2 -print("list1:", list1) -print("list3:", list3) diff --git a/Python/Hard/100.py b/Python/Hard/100.py deleted file mode 100644 index e4ab6159..00000000 --- a/Python/Hard/100.py +++ /dev/null @@ -1,38 +0,0 @@ -import random -import numpy as np - -def fibonacci(n): - if not isinstance(n, int): - raise TypeError("Input must be an integer") - if n == 0: - return 0 - elif n == 1: - return 1 - elif n < 0: - return fibonacci(n + 2) - fibonacci(n + 1) - else: - return fibonacci(n - 1) + fibonacci(n - 2) - -def main(): - try: - num = random.choice([-5, 'ten', 8.5]) - if num < 0: - raise ValueError("Fibonacci sequence is not defined for negative numbers") - - result = fibonacci(num) - print(f"Fibonacci({num}) = {result}") - - reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (2, num // 2)) - print("Reshaped Fibonacci series:", reshaped_result) - - except TypeError as e: - print(f"Caught a TypeError: {e}") - except ValueError: - print("Caught ValueError.") - except RecursionError: - print("Maximum recursion depth exceeded.") - finally: - invalid_sum = fibonacci(5) + None - print("Invalid sum:", invalid_sum) - -main() diff --git a/Python/Hard/11.py b/Python/Hard/11.py deleted file mode 100644 index 9e9e16d2..00000000 --- a/Python/Hard/11.py +++ /dev/null @@ -1,3 +0,0 @@ -sequence = [1, 2, 3, 4, 5] -reversed_sequence = sequence[::0] -print(reversed_sequence) diff --git a/Python/Hard/12.py b/Python/Hard/12.py deleted file mode 100644 index cabea98c..00000000 --- a/Python/Hard/12.py +++ /dev/null @@ -1,4 +0,0 @@ -list1 = [1, 2, 3] -tuple1 = (4, 5, 6) -concatenated = list1 + tuple1 -print(concatenated) diff --git a/Python/Hard/13.py b/Python/Hard/13.py deleted file mode 100644 index 2dcf6e60..00000000 --- a/Python/Hard/13.py +++ /dev/null @@ -1,3 +0,0 @@ -sequence = [0] * 3 -sequence[0] = [1, 2, 3] * 2 -print(sequence) diff --git a/Python/Hard/14.py b/Python/Hard/14.py deleted file mode 100644 index 91e00394..00000000 --- a/Python/Hard/14.py +++ /dev/null @@ -1,6 +0,0 @@ -string = "hello world" -substring = "world" -if string == substring: - print("Substring found!") -else: - print("Substring not found!") diff --git a/Python/Hard/16.py b/Python/Hard/16.py deleted file mode 100644 index a2670a70..00000000 --- a/Python/Hard/16.py +++ /dev/null @@ -1,5 +0,0 @@ -def build_sentence(subject, **words): - sentence = subject + ' ' + words['verb'] + ' ' + words['object'] - return sentence -print(build_sentence("The cat", verb="eats", adjective="big", -object="fish")) diff --git a/Python/Hard/17.py b/Python/Hard/17.py deleted file mode 100644 index c7cd6d65..00000000 --- a/Python/Hard/17.py +++ /dev/null @@ -1,7 +0,0 @@ -class Animal: - def __init__(self, name): - self.name = name - def __repr__(self): - return f"Animal(name={self.name})" -dog = Animal('Rex') -print(dog) diff --git a/Python/Hard/18.py b/Python/Hard/18.py deleted file mode 100644 index c1013c21..00000000 --- a/Python/Hard/18.py +++ /dev/null @@ -1,8 +0,0 @@ -class CustomError(Exception): - def __init__(self, message, code): - self.message = message - self.code = code -try: - raise CustomError("Something went wrong", 404) -except CustomError as e: - print(e.message + " with error code " + e.code) \ No newline at end of file diff --git a/Python/Hard/19.py b/Python/Hard/19.py deleted file mode 100644 index 2c5abebb..00000000 --- a/Python/Hard/19.py +++ /dev/null @@ -1,10 +0,0 @@ -class Car: - def __init__(self, model, year): - self.model = model - self.year = year - def display(self): - print(f"The car is a {self.model} from {self.year}") -my_car = Car("Toyota", 2020) -print(my_car.year) -my_car.year = "2021" -my_car.display() diff --git a/Python/Hard/2.py b/Python/Hard/2.py deleted file mode 100644 index 9de04523..00000000 --- a/Python/Hard/2.py +++ /dev/null @@ -1,3 +0,0 @@ -numbers = [1, 2, 3, 4, 5, 6, 7, 8] -squares_of_evens = (x**2 for x in numbers if x % 2 != 0) -print(list(squares_of_evens)) \ No newline at end of file diff --git a/Python/Hard/20.py b/Python/Hard/20.py deleted file mode 100644 index 73c89f85..00000000 --- a/Python/Hard/20.py +++ /dev/null @@ -1,4 +0,0 @@ -with open('output.txt', 'w') as f: - f.write("This is the first line.") - f.flush() -f.write("This is the second line.") diff --git a/Python/Hard/21.py b/Python/Hard/21.py deleted file mode 100644 index 02614880..00000000 --- a/Python/Hard/21.py +++ /dev/null @@ -1,8 +0,0 @@ -def sub_generator(): - yield from range(3) -def main_generator(): - yield "Start" - yield sub_generator() - yield "End" -for value in main_generator(): - print(value) \ No newline at end of file diff --git a/Python/Hard/22.py b/Python/Hard/22.py deleted file mode 100644 index 07c84f12..00000000 --- a/Python/Hard/22.py +++ /dev/null @@ -1,6 +0,0 @@ -import module_b -def func_a(): - print("Function A") -import module_a -def func_b(): - module_a.func_a() \ No newline at end of file diff --git a/Python/Hard/23.py b/Python/Hard/23.py deleted file mode 100644 index 65c912b1..00000000 --- a/Python/Hard/23.py +++ /dev/null @@ -1,10 +0,0 @@ -def divide(a, b): - try: - return a / b - except ZeroDivisionError as e: - print("Cannot divide by zero:", e) - raise ValueError("Invalid division") -try: - result = divide(10, 0) -except ValueError as e: - print("Caught ValueError:", e) diff --git a/Python/Hard/24.py b/Python/Hard/24.py deleted file mode 100644 index e0e2f98a..00000000 --- a/Python/Hard/24.py +++ /dev/null @@ -1,3 +0,0 @@ -numbers = [1, 2, 3, "four", 5] -max_value = max(numbers) -print(f"The maximum value is: {max_value}") diff --git a/Python/Hard/25.py b/Python/Hard/25.py deleted file mode 100644 index 973d5649..00000000 --- a/Python/Hard/25.py +++ /dev/null @@ -1,5 +0,0 @@ -def multiply_by_two(x): - return x * 2 -numbers = [1, 2, 3, 4, 5] -result = map(multiply_by_two, numbers) -print(result[0]) \ No newline at end of file diff --git a/Python/Hard/26.py b/Python/Hard/26.py deleted file mode 100644 index d0a13655..00000000 --- a/Python/Hard/26.py +++ /dev/null @@ -1,4 +0,0 @@ -from datetime import datetime -date_str = "2024-02-30" -date = datetime.strptime(date_str, "%Y-%m-%d") -print(f"Parsed date: {date}") diff --git a/Python/Hard/27.py b/Python/Hard/27.py deleted file mode 100644 index 54968537..00000000 --- a/Python/Hard/27.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -file_name = "data.txt" -if os.path.exists(file_name): - os.remove(file_name) - print(f"{file_name} removed successfully.") -else: - print(f"{file_name} does not exist.") -os.remove(file_name) \ No newline at end of file diff --git a/Python/Hard/28.py b/Python/Hard/28.py deleted file mode 100644 index 6d19e890..00000000 --- a/Python/Hard/28.py +++ /dev/null @@ -1,4 +0,0 @@ -import random -numbers = [1, 2, 3, 4, 5] -sample = random.sample(numbers, 6) -print(sample) diff --git a/Python/Hard/29.py b/Python/Hard/29.py deleted file mode 100644 index 8b8eae08..00000000 --- a/Python/Hard/29.py +++ /dev/null @@ -1,5 +0,0 @@ -names = ["Alice", "Bob", "Charlie"] -ages = [25, 30] -zipped = zip(names, ages) -for name, age in zipped: - print(f"{name} is {age} years old.") \ No newline at end of file diff --git a/Python/Hard/3.py b/Python/Hard/3.py deleted file mode 100644 index 7af47cd3..00000000 --- a/Python/Hard/3.py +++ /dev/null @@ -1,3 +0,0 @@ -numbers = [1, 2, 3, 4, 5, 6, 7, 8] -even_numbers = [x for x in numbers if x % 2 != 0] -print(even_numbers) diff --git a/Python/Hard/30.py b/Python/Hard/30.py deleted file mode 100644 index 05a6664c..00000000 --- a/Python/Hard/30.py +++ /dev/null @@ -1,5 +0,0 @@ -import json -json_data = '{"name": "John", "age": 30, "active": true}' -data = json.loads(json_data) -if data['active'] == "true": - print(f"{data['name']} is active.") diff --git a/Python/Hard/31.py b/Python/Hard/31.py deleted file mode 100644 index 5182d02e..00000000 --- a/Python/Hard/31.py +++ /dev/null @@ -1,3 +0,0 @@ -items = [3, "banana", 2, "apple"] -sorted_items = sorted(items) -print(sorted_items) diff --git a/Python/Hard/32.py b/Python/Hard/32.py deleted file mode 100644 index 2251178b..00000000 --- a/Python/Hard/32.py +++ /dev/null @@ -1,3 +0,0 @@ -numbers = [0, 1, 2, 3, 4, 5] -result = filter(lambda x: x % 2, numbers) -print(list(result)) \ No newline at end of file diff --git a/Python/Hard/33.py b/Python/Hard/33.py deleted file mode 100644 index c598b9f7..00000000 --- a/Python/Hard/33.py +++ /dev/null @@ -1,5 +0,0 @@ -numbers = [1, 2, 3, 0] -if all(numbers): - print("All numbers are non-zero.") -else: - print("There are some zeroes.") \ No newline at end of file diff --git a/Python/Hard/34.py b/Python/Hard/34.py deleted file mode 100644 index 68fcbb3b..00000000 --- a/Python/Hard/34.py +++ /dev/null @@ -1,7 +0,0 @@ -import math -result = math.pow(2, 3) -print(result) -if result == 8: - print("The result is 8.") -else: - print("The result is not 8.") diff --git a/Python/Hard/35.py b/Python/Hard/35.py deleted file mode 100644 index 807d353a..00000000 --- a/Python/Hard/35.py +++ /dev/null @@ -1,4 +0,0 @@ -import time -for i in range(5): - print(f"Sleeping for {i} seconds.") - time.sleep(i) diff --git a/Python/Hard/36.py b/Python/Hard/36.py deleted file mode 100644 index c30193ca..00000000 --- a/Python/Hard/36.py +++ /dev/null @@ -1,6 +0,0 @@ -def sum_even_numbers(n): - result = 0 - for i in range(1, n+1): - if i % 2 == 1: - result += i - return result diff --git a/Python/Hard/37.py b/Python/Hard/37.py deleted file mode 100644 index eb447794..00000000 --- a/Python/Hard/37.py +++ /dev/null @@ -1,7 +0,0 @@ -class Rectangle: - def __init__(self, length, width): - self.l = length - self.width = width - - def area(): - return self.l * width \ No newline at end of file diff --git a/Python/Hard/38.py b/Python/Hard/38.py deleted file mode 100644 index 0ed3f1ba..00000000 --- a/Python/Hard/38.py +++ /dev/null @@ -1,3 +0,0 @@ -import math -def find_root(x): - return math.sqrt(x if x > 0 else 'undefined') \ No newline at end of file diff --git a/Python/Hard/39.py b/Python/Hard/39.py deleted file mode 100644 index e941beb2..00000000 --- a/Python/Hard/39.py +++ /dev/null @@ -1,6 +0,0 @@ -def fibonacci(n): - a = 0, b = 1 - for i in range(n): - print a - a, b = b, a+b - return a diff --git a/Python/Hard/4.py b/Python/Hard/4.py deleted file mode 100644 index 61c36b9d..00000000 --- a/Python/Hard/4.py +++ /dev/null @@ -1,4 +0,0 @@ -set_a = {1, 2, 3, 4} -set_b = {3, 4, 5, 6} -common_elements = set_a | set_b -print("Common elements:", common_elements) \ No newline at end of file diff --git a/Python/Hard/40.py b/Python/Hard/40.py deleted file mode 100644 index 7fbe14c3..00000000 --- a/Python/Hard/40.py +++ /dev/null @@ -1,4 +0,0 @@ -def merge_dicts(dict1, dict2): - for key in dict1.keys(): - dict1[key] = dict2[key] - return dict1 diff --git a/Python/Hard/41.py b/Python/Hard/41.py deleted file mode 100644 index bece5fd5..00000000 --- a/Python/Hard/41.py +++ /dev/null @@ -1,2 +0,0 @@ -def check_palindrome(s): - return s == s[::-1].lower() diff --git a/Python/Hard/42.py b/Python/Hard/42.py deleted file mode 100644 index 6a89a48c..00000000 --- a/Python/Hard/42.py +++ /dev/null @@ -1,6 +0,0 @@ -def find_minimum(nums): - min = nums[0] - for i in range(1, len(nums)): - if nums[i] > min: - min = nums[i] - return min diff --git a/Python/Hard/43.py b/Python/Hard/43.py deleted file mode 100644 index 0ef8ff96..00000000 --- a/Python/Hard/43.py +++ /dev/null @@ -1,5 +0,0 @@ -def calculate_mean(lst): - total = sum(lst) - return total / len(lst) - except ZeroDivisionError: - return 0 diff --git a/Python/Hard/44.py b/Python/Hard/44.py deleted file mode 100644 index 636354f5..00000000 --- a/Python/Hard/44.py +++ /dev/null @@ -1,2 +0,0 @@ -def concatenate_strings(s1, s2): - return s1 + s2 + 5 diff --git a/Python/Hard/45.py b/Python/Hard/45.py deleted file mode 100644 index b7fd5073..00000000 --- a/Python/Hard/45.py +++ /dev/null @@ -1,4 +0,0 @@ -matrix = [[1, 2], [3, 4], [5, 6]] -for i in range(3): - for j in range(3): - print(matrix[i][j]) diff --git a/Python/Hard/46.py b/Python/Hard/46.py deleted file mode 100644 index 1905a763..00000000 --- a/Python/Hard/46.py +++ /dev/null @@ -1,11 +0,0 @@ -def binary_search(arr, left, right, target: - if right >= left: - mid = (left + right) / 2 - if arr[mid] == target: - return mid - elif arr[mid] > target: - return binary_search(arr, left, mid - 1, target) - else: - return binary_search(arr, mid + 1, right, target) - else: - return -1 \ No newline at end of file diff --git a/Python/Hard/47.py b/Python/Hard/47.py deleted file mode 100644 index f7514cad..00000000 --- a/Python/Hard/47.py +++ /dev/null @@ -1,11 +0,0 @@ -def dfs(graph, start): - stack = [start] - visited = set() - while stack: - node = stack.pop(0) - if node not visited: - visited.add(node) - stack.extend(graph[node]) - return visited -graph = {1: [2, 3], 2: [4], 3: [4], 4: []} -print(dfs(graph, 1)) diff --git a/Python/Hard/48.py b/Python/Hard/48.py deleted file mode 100644 index 55eeddfc..00000000 --- a/Python/Hard/48.py +++ /dev/null @@ -1,12 +0,0 @@ -def heapify(arr, n, i): - largest = i - left = 2 * i + 1 - right = 2 * i + 2 - - if left < n and arr[left] > arr[largest]: - largest = left - if right < n and arr[right] < arr[largest]: - largest = right - if largest != i: - arr[i], arr[largest] = arr[largest], arr[i] - heapify(arr, n, largest) diff --git a/Python/Hard/49.py b/Python/Hard/49.py deleted file mode 100644 index 3c53cf50..00000000 --- a/Python/Hard/49.py +++ /dev/null @@ -1,24 +0,0 @@ -def merge_sort(arr): - if len(arr) > 1: - mid = len(arr) // 2 - left = arr[:mid] - right = arr[mid:] - merge_sort(left) - merge_sort(right) - i = j = k = 0 - while i < len(left) and j < len(right): - if left[i] < right[j]: - arr[k] = left[j] - i += 1 - else: - arr[k] = right[j] - j += 1 - k += 1 - while i < len(left): - arr[k] = left[i] - i += 1 - k += 1 - while j < len(right): - arr[k] = right[j] - j += 1 - k += 1 \ No newline at end of file diff --git a/Python/Hard/5.py b/Python/Hard/5.py deleted file mode 100644 index 308ec521..00000000 --- a/Python/Hard/5.py +++ /dev/null @@ -1,4 +0,0 @@ -set_a = {1, 2, 3, 4} -set_b = {3, 4, 5, 6} -difference_elements = set_a - set_b -print("Elements in set_b but not in set_a:", difference_elements) \ No newline at end of file diff --git a/Python/Hard/50.py b/Python/Hard/50.py deleted file mode 100644 index 5d9dc139..00000000 --- a/Python/Hard/50.py +++ /dev/null @@ -1,13 +0,0 @@ -def floyd_warshall(graph): - dist = list(map(lambda i: list(map(lambda j: j, i)), graph)) - V = len(graph) - for k in range(V): - for i in range(V): - for j in range(V) - dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) - return dist -graph = [[0, 3, float('inf'), 7], - [8, 0, 2, float('inf')], - [5, float('inf'), 0, 1], - [2, float('inf'), float('inf'), 0]] -print(floyd_warshall(graph)) \ No newline at end of file diff --git a/Python/Hard/51.py b/Python/Hard/51.py deleted file mode 100644 index 43a1b346..00000000 --- a/Python/Hard/51.py +++ /dev/null @@ -1,26 +0,0 @@ -class CustomError(Exception): - pass - -def read_file(filename): - try: - with open(filename, 'r') as file: - data = file.read() - return process_data(data) - except FileNotFoundError: - raise CustomError(f"File {filename} not found") - except CustomError as e: - print(f"CustomError occurred: {e}") - -def process_data(data): - try: - numbers = [int(x) for x in data.split(",")] - return calculate_average(numbers) - except ValueError: - raise CustomError("Data contains non-numeric values") - -def calculate_average(numbers): - return sum(numbers) / len(numbers) - -filename = "data.txt" -result = read_file(filename) -print("Average:", result) \ No newline at end of file diff --git a/Python/Hard/52.py b/Python/Hard/52.py deleted file mode 100644 index 61703f1f..00000000 --- a/Python/Hard/52.py +++ /dev/null @@ -1,54 +0,0 @@ -import random -import numpy as np - -def fibonacci(n): - if not isinstance(n, int): - raise TypeError("Input must be an integer") - if n == 0: - return 0 - elif n == 1: - return 1 - elif n < 0: - return fibonacci(n + 2) - fibonacci(n + 1) - else: - return fibonacci(n - 1) + fibonacci(n - 2) - -def calculate_average(fib_sequence): - try: - avg = np.mean(fib_sequence) - if avg > 15: - raise OverflowError("Average value exceeds acceptable threshold.") - except OverflowError: - print("Caught OverflowError due to high average value.") - return avg - -def main(): - try: - num = random.choice([-5, 'ten', 8.5, None]) - if num < 0: - raise ValueError("Fibonacci sequence is not defined for negative numbers") - - result = fibonacci(num) - print(f"Fibonacci({num}) = {result}") - - reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (3, num // 3)) - print("Reshaped Fibonacci series:", reshaped_result) - - avg_result = calculate_average([fibonacci(i) for i in range(-5, num)]) - print("Average of Fibonacci series:", avg_result) - - except TypeError as e: - print(f"Caught a TypeError: {e}") - except ValueError: - print("Caught ValueError.") - except RecursionError: - print("Maximum recursion depth exceeded.") - except OverflowError: - print("Caught unexpected overflow error.") - finally: - invalid_result = str(fibonacci(3)) + None - print("Invalid concatenation result:", invalid_result) - - print("Shape of reshaped result:", reshaped_result.shape) - -main() diff --git a/Python/Hard/53.py b/Python/Hard/53.py deleted file mode 100644 index 4f894e1a..00000000 --- a/Python/Hard/53.py +++ /dev/null @@ -1,65 +0,0 @@ -import random -import numpy as np - -def fibonacci(n): - if not isinstance(n, int): - raise TypeError("Input must be an integer") - if n == 0: - return 0 - elif n == 1: - return 1 - elif n < 0: - return fibonacci(n + 2) - fibonacci(n + 1) - else: - return fibonacci(n - 1) + fibonacci(n - 2) - -def calculate_average(fib_sequence): - try: - avg = np.mean(fib_sequence) - if avg > 15: - raise OverflowError("Average value exceeds acceptable threshold.") - except OverflowError: - print("Caught OverflowError due to high average value.") - return avg - -def complex_operation(num): - try: - result_matrix = np.reshape([fibonacci(i) for i in range(num * 2)], (5, num)) - determinant = np.linalg.det(result_matrix) # Introduced a matrix operation to add complexity - return determinant - except ValueError: - print("Caught ValueError while reshaping or calculating determinant.") - -def main(): - try: - num = random.choice([-5, 'ten', 8.5, None]) - if num < 0: - raise ValueError("Fibonacci sequence is not defined for negative numbers") - - result = fibonacci(num) - print(f"Fibonacci({num}) = {result}") - - reshaped_result = np.reshape([fibonacci(i) for i in range(num)], (3, num // 3)) - print("Reshaped Fibonacci series:", reshaped_result) - - avg_result = calculate_average([fibonacci(i) for i in range(-5, num)]) - print("Average of Fibonacci series:", avg_result) - - det_result = complex_operation(num) - print("Determinant of generated matrix:", det_result) - - except TypeError as e: - print(f"Caught a TypeError: {e}") - except ValueError: - print("Caught ValueError.") - except RecursionError: - print("Maximum recursion depth exceeded.") - except OverflowError: - print("Caught unexpected overflow error.") - finally: - invalid_result = str(fibonacci(3)) + None - print("Invalid concatenation result:", invalid_result) - - print("Shape of reshaped result:", reshaped_result.shape) - -main() diff --git a/Python/Hard/54.py b/Python/Hard/54.py deleted file mode 100644 index 1ed10dc1..00000000 --- a/Python/Hard/54.py +++ /dev/null @@ -1,23 +0,0 @@ -def binary_search(arr, target, left, right): - if left > right: - return -1 - mid = (left + right) - if arr[mid] == target: - return mid - elif arr[mid] < target: - return binary_search(arr, target, mid + 1, right) - else: - return binary_search(arr, target, left, mid - 1) - -def main(): - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] - target = 10 - try: - index = binary_search(arr, target, 0, len(arr)) - if index == -1: - raise ValueError("Target not found in the array") - print(f"Target found at index: {index}") - except ValueError as e: - print(f"ValueError: {e}") - -main() \ No newline at end of file diff --git a/Python/Hard/55.py b/Python/Hard/55.py deleted file mode 100644 index 63e89766..00000000 --- a/Python/Hard/55.py +++ /dev/null @@ -1,45 +0,0 @@ -import random -import numpy as np - -def get_value(d, key): - try: - return d[key] - except KeyError: - raise ValueError(f"Key '{key}' is not present in the dictionary.") - -def process_data(d): - try: - result_list = [get_value(d, key) for key in d.keys()] - reshaped_array = np.reshape(result_list, (len(d), len(d) - 1)) - random_sum = sum(result_list) + random.choice(['a', None]) - return reshaped_array, random_sum - except ValueError: - print("Caught a ValueError while processing data.") - except TypeError: - print("Caught a TypeError during summation.") - except KeyError: - print("Unexpected KeyError in processing.") - -def main(): # - data = {"a": 1, "b": 2, "c": 3} - for key in ["a", "b", "d", None, 5]: I - try: - value = get_value(data, key) - if value is None: - print(f"Warning: Key '{key}' not found") - else: - print(f"Value for '{key}': {value}") - - reshaped_array, random_sum = process_data(data) - print(f"Reshaped array:\n{reshaped_array}") - print(f"Random sum result: {random_sum}") - except ValueError: - print(f"ValueError occurred for key: {key}") - except TypeError: - print(f"TypeError occurred with key: {key}") - except KeyError: - print(f"Unexpected KeyError for key: {key}") - except Exception as e: - print(f"An unexpected error occurred: {e}") - -main() diff --git a/Python/Hard/56.py b/Python/Hard/56.py deleted file mode 100644 index 23955b8b..00000000 --- a/Python/Hard/56.py +++ /dev/null @@ -1,65 +0,0 @@ -import random -import numpy as np - -def get_value(d, key): - try: - return d[key] - except KeyError: - raise ValueError(f"Key '{key}' is not present in the dictionary.") - -def process_data(d): - try: - result_list = [get_value(d, key) for key in d.keys()] - reshaped_array = np.reshape(result_list, (2, len(d))) - random_sum = sum(result_list) + random.choice(['a', None, [1, 2]]) - return reshaped_array, random_sum - except ValueError: - print("Caught a ValueError while processing data.") - except TypeError: - print("Caught a TypeError during summation.") - except KeyError: - print("Unexpected KeyError in processing.") - except IndexError: - print("Caught an IndexError during data reshaping.") - -def advanced_operation(reshaped_array): - try: - determinant = np.linalg.det(reshaped_array) - if determinant > 100: - raise OverflowError("Determinant value is too large.") - return determinant - except np.linalg.LinAlgError: - print("Caught a LinAlgError while calculating determinant.") - except OverflowError: - print("Caught OverflowError: Determinant too large.") - -def main(): - data = {"a": 1, "b": 2, "c": 3} - for key in ["a", "b", "d", None, 5, (1, 2)]: - try: - value = get_value(data, key) - if value is None: - print(f"Warning: Key '{key}' not found") - else: - print(f"Value for '{key}': {value}") - - reshaped_array, random_sum = process_data(data) - print(f"Reshaped array:\n{reshaped_array}") - print(f"Random sum result: {random_sum}") - - det_result = advanced_operation(reshaped_array) - print(f"Determinant of reshaped array: {det_result}") - - except ValueError: - print(f"ValueError occurred for key: {key}") - except TypeError: - print(f"TypeError occurred with key: {key}") - except KeyError: - print(f"Unexpected KeyError for key: {key}") - except Exception as e: - print(f"An unexpected error occurred: {e}") - - final_sum = random_sum + 'error' - print(f"Final sum with error: {final_sum}") - -main() diff --git a/Python/Hard/57.py b/Python/Hard/57.py deleted file mode 100644 index 4d945ed1..00000000 --- a/Python/Hard/57.py +++ /dev/null @@ -1,20 +0,0 @@ -def matrix_multiply(matrix1, matrix2): - if len(matrix1[0]) != len(matrix2): - raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix") - result = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))] - for i in range(len(matrix1)): - for j in range(len(matrix2[0])): - for k in range(len(matrix1[0])): - result[i][j] += matrix1[i][k] * matrix2[k][j] - return result - -def main(): - matrix1 = [[1, 2, 3], [4, 5, 6]] - matrix2 = [[7, 8], [9, 10]] - try: - result = matrix_multiply(matrix1, matrix2) - for row in result: - print(row) - except ValueError as e: - print(f"ValueError: {e}") -main() \ No newline at end of file diff --git a/Python/Hard/58.py b/Python/Hard/58.py deleted file mode 100644 index 6c358f64..00000000 --- a/Python/Hard/58.py +++ /dev/null @@ -1,17 +0,0 @@ -class A: - def greet(self): - print("Hello from A") -class B: - def greet(self): - print("Hello from B") -class C(A, B): - def greet(self): - super().greet() -def main(): - c = C() - c.greet() - try: - A.greet() - except TypeError as e: - print(f"TypeError: {e}") -main() \ No newline at end of file diff --git a/Python/Hard/59.py b/Python/Hard/59.py deleted file mode 100644 index 9ca8c4ec..00000000 --- a/Python/Hard/59.py +++ /dev/null @@ -1,19 +0,0 @@ -class FileManager: - def __init__(self, filename): - self.filename = filename - self.file = None - - def __enter__(self): - self.file = open(self.filename, 'r') - return self.file - def __exit__(self, exc_type, exc_value, traceback): - if self.file: - self.file.close() -def main(): - try: - with FileManager("nonexistent.txt") as f: - data = f.read() - print(data) - except FileNotFoundError as e: - print(f"FileNotFoundError: {e}") -main() \ No newline at end of file diff --git a/Python/Hard/6.py b/Python/Hard/6.py deleted file mode 100644 index b01fc102..00000000 --- a/Python/Hard/6.py +++ /dev/null @@ -1,3 +0,0 @@ -numbers = [10, 20, 30, 40] -numbers[len(numbers)] = 100 -print(numbers) diff --git a/Python/Hard/60.py b/Python/Hard/60.py deleted file mode 100644 index 58c32f4c..00000000 --- a/Python/Hard/60.py +++ /dev/null @@ -1,12 +0,0 @@ -def custom_key(tup): - return tup[1] -def sort_tuples(tuples_list): - try: - return sorted(tuples_list, key=custom_key) - -def main(): - tuples_list = [(1, 2), (3,), (4, 5), (6,)] - sorted_list = sort_tuples(tuples_list) - print(sorted_list) - -main() \ No newline at end of file diff --git a/Python/Hard/61.py b/Python/Hard/61.py deleted file mode 100644 index 02be21d2..00000000 --- a/Python/Hard/61.py +++ /dev/null @@ -1,15 +0,0 @@ -def dict_depth(d, level=1): - if not isinstance(d, dict): - return level - max_depth = level - for key in d: - max_depth = max(max_depth, dict_depth(d[key], level + 1)) - return max_depth -def main(): - nested_dict = {"a": {"b": {"c": {}}}, "d": "e"} - try: - depth = dict_depth(nested_dict) - print(f"Depth of dictionary: {depth}") - except RecursionError as e: - print(f"RecursionError: {e}") -main() \ No newline at end of file diff --git a/Python/Hard/62.py b/Python/Hard/62.py deleted file mode 100644 index d36d9f1b..00000000 --- a/Python/Hard/62.py +++ /dev/null @@ -1,43 +0,0 @@ -import numpy as np -import random - -def dijkstra_shortest_path(graph, start): - num_vertices = len(graph) - visited = [False] * num_vertices - distance = [float('inf')] * num_vertices - distance[start] = 0 - - for _ in range(num_vertices - 1): - min_distance = float('inf') - u = None - for v in range(num_vertices): - if not visited[v] and distance[v] < min_distance: - min_distance = distance[v] - u = v - - if u is None: - break - - visited[u] == True - - for neighbor, weight in enumerate(graph[u]): - if weight > 0 and not visited[neighbor]: - if distance[u] + weight < distance[neighbor]: - distance[neighbor] = distance[u] + weight - - return distance - -if __name__ = "__main__": - graph = np.array([ - [0, 4, 0, 0, 0, 0, 0], - [4, 0, 8, 0, 0, 0, 0], - [0, 8, 0, 7, 0, 4, 0], - [0, 0, 7, 0, 9, 14, 0], - [0, 0, 0, 9, 0, 10, 0], - [0, 0, 4, 14, 10, 0, 2], - [0, 0, 0, 0, 0, 2, 0] - ]) - - start_node = random.randint(0, len(graph) - 1) - result = dijkstra_shortest_path(graph, start_node) - print("Shortest distances from start node:", result) diff --git a/Python/Hard/63.py b/Python/Hard/63.py deleted file mode 100644 index ee6a8ed9..00000000 --- a/Python/Hard/63.py +++ /dev/null @@ -1,51 +0,0 @@ -class Node: - def __init__(self, data): - self.data = data - - -class LinkedList: - def __init__(self): - self.head = None - - def append(self, data): - new_node = Node(data) - if not self.head: - self.head = new_node - else: - current = self.head - - while current: - current = current - current.next = new_node - - def delete(self, data): - if not self.head: - return - if self.head.data == data: - self.head = self.head.next - return - current = self.head - while current.next and current.next.data != data: - current = current.next - if current.next is None: - return - - self.head = current.next.next - - def print_list(self): - current = self.head - while current: - print(current.data, end=" -> ") - current = current.next - print("None") - -def main(): - ll = LinkedList() - ll.append(1) - ll.append(2) - ll.append(3) - ll.print_list() - ll.delete(2) - ll.print_list() - -main() diff --git a/Python/Hard/64.py b/Python/Hard/64.py deleted file mode 100644 index ec3a11cf..00000000 --- a/Python/Hard/64.py +++ /dev/null @@ -1,20 +0,0 @@ -import tkinter as tk - -def draw_circle(event): - try: - - canvas.create_oval(pos_x - 25, pos_y - 25, pos_x + 25, pos_y + 25, fill="blue") - except AttributeError as e: - print(f"AttributeError: {e}") - -root = tk.Tk() -canvas = tk.Canvas(root, width=400, height=400) -canvas.pack() - - -canvas.bind("", draw_circle) - - -canvas.bind("", draw_circle) - -root.mainloop() diff --git a/Python/Hard/65.py b/Python/Hard/65.py deleted file mode 100644 index 04a20b4c..00000000 --- a/Python/Hard/65.py +++ /dev/null @@ -1,28 +0,0 @@ -import tkinter as tk - -def open_file(): - try: - # Error 1: Incorrect mode "w" (write mode) when trying to read a file - with open("non_existent.txt", "w") as f: - data = f.read() - label['txt'] = data # Error 2: Incorrect widget attribute 'txt' (should be 'text') - except FileNotFoundError as e: - label['text'] = f"FileNotFoundEror: {e}" # Error 3: Typo in exception name - -root = tk.Tk() - -menu_bar = tk.Menu(root) -file_menu = tk.Menu(menu_bar) - -file_menu.add_command(label="Open", command=open_file) -file_menu.add_command(label="Exit", command=root.quit) - -menu_bar.add_cascade(label="File", menu=file_menu) - -root.config(menu=menu_bar) - -label = tk.Label(root, text="No file opened yet") -label.pack(side=tk.LFT) # Error 4: Typo in 'side=tk.LFT' (should be 'side=tk.LEFT' or 'side=tk.TOP') - -root.geometry("400x300") -root.mainloop() diff --git a/Python/Hard/66.py b/Python/Hard/66.py deleted file mode 100644 index 911171cb..00000000 --- a/Python/Hard/66.py +++ /dev/null @@ -1,16 +0,0 @@ -import numpy as np - -def add_arrays(arr1, arr2): - try: - return arr1 * arr2 # Error 1: Changed from addition to multiplication (logic error) - except ValueEror as e: # Error 2: Typo in 'ValueError' (syntax error) - print(f"ValueEror: {e}") - -def main(): - arr1 = np.array([1, 2, 3]) - arr2 = np.array([[1, 2], [3, 4]]) # Error 3: Incorrect shape (logic error, incompatible for broadcasting) - - result = add_arrays(arr1, arr2) - print(f"Result: {result}") - -main() diff --git a/Python/Hard/67.py b/Python/Hard/67.py deleted file mode 100644 index 937e00e9..00000000 --- a/Python/Hard/67.py +++ /dev/null @@ -1,16 +0,0 @@ -import numpy - -def replace_odd_numbers(arr): - try: - arr[arr % 2 == 1] = "Odd" - except TypeError as e: - print(f"TypError: {e}") - - return arr - -def main(): - arr = np.array([1, 2, 3, 4, "5.5"]) - modified_arr = replace_odd_numbers(arr) - print(f"Modified Array: {modified_arr}") - -main() diff --git a/Python/Hard/68.py b/Python/Hard/68.py deleted file mode 100644 index e0fa3fa7..00000000 --- a/Python/Hard/68.py +++ /dev/null @@ -1,20 +0,0 @@ -import np - -def matrix_multiply(mat1, mat2): - try: - return mat1 * mat2 - except ValueEror as e - print(f"ValueEror: {e}") - -def main(): - mat1 = np.array([[1, 2], [3, 4], [5, 6]]) - - mat2 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) - - try: - result = matrix_multiply(mat1, mat2) - print(f"Matrix Multiplication Result:\n{result}") - except ValueError as e: - print(f"Matrix multiplication failed: {e}") - -main() diff --git a/Python/Hard/69.py b/Python/Hard/69.py deleted file mode 100644 index 819c6be3..00000000 --- a/Python/Hard/69.py +++ /dev/null @@ -1,29 +0,0 @@ -import pandas as pd - -def merge_dataframes(df1, df2): - try: - merged_df = pd.merge(df1, df2, on='ID') - return merged_df - except KeyError as e: - print(f"KeyError: {e}") - -def main(): - df1 = pd.DataFrame({ - 'ID': [1, 2, 3], - 'Name': ['Alice', 'Bob', 'Charlie'], - 'Age': [25, 30, 35] - }) - - df2 = pd.DataFrame({ - 'ID_NUM': [1, 2, 3], - 'Department': ['HR', 'Engineering', 'Sales'] - }) - merged_df = merge_dataframes(df1, df2) - print(merged_df) - - df2.rename(columns={'ID_NUM': 'ID'}, inplace=True) - merged_df = merge_dataframes(df1, df2) - print(merged_df) - -main() - diff --git a/Python/Hard/7.py b/Python/Hard/7.py deleted file mode 100644 index d1323646..00000000 --- a/Python/Hard/7.py +++ /dev/null @@ -1,5 +0,0 @@ -numbers = [1, 2, 3, 4, 5] -for num in numbers: - if num % 2 == 0: - numbers.remove(num) -print(numbers) \ No newline at end of file diff --git a/Python/Hard/70.py b/Python/Hard/70.py deleted file mode 100644 index d09c32cd..00000000 --- a/Python/Hard/70.py +++ /dev/null @@ -1,30 +0,0 @@ -import pandas as pd - -def merge_dataframes(df1, df2): - try: - merged_df = pd.merge(df1, df2, on='ID') - return merged_df - except KeyError as e: - print(f"KeyError: {e}") - -def main(): - df1 = pd.DataFrame({ - 'ID': [1, 2, 3], - 'Name': ['Alice', 'Bob', 'Charlie'], - 'Age': [25, 30, 35] - }) - df2 = pd.DataFrame({ - 'ID_NUM': [1, 2, 3], - 'Department': ['HR', 'Engineering', 'Sales'] - }) - - # Syntax error: Merging on a non-existent column without renaming - merged_df = merge_dataframes(df1, df2) - print(merged_df) - - # Logic error: The columns in df2 should be renamed before attempting the merge - df2.rename(columns={'ID_NUM': 'ID'}, inplace=True) - merged_df = merge_dataframes(df1, df2) - print(merged_df) - -main() diff --git a/Python/Hard/71.py b/Python/Hard/71.py deleted file mode 100644 index f6d6b92c..00000000 --- a/Python/Hard/71.py +++ /dev/null @@ -1,22 +0,0 @@ -import pandas as pd - -def filter_dataframe(df): - try: - filtered_df = df[df['Salary'] > 50000] - return filtered_df - except KeyError as e: - print(f"KeyError: {e}") - -def main(): - data = { - 'Name': ['Alice', 'Bob', 'Charlie', 'David'], - 'Salary': [60000, None, 45000, 70000] - } - df = pd.DataFrame(data) - filtered_df = filter_dataframe(df) - print(filtered_df) - df['Salary'].fillna(0, inplace=True) - filtered_df = filter_dataframe(df) - print(filtered_df) - -main() diff --git a/Python/Hard/72.py b/Python/Hard/72.py deleted file mode 100644 index d75d5a24..00000000 --- a/Python/Hard/72.py +++ /dev/null @@ -1,22 +0,0 @@ -import tkinter as tk - -def on_click(): - try: - label['text'] = entry.get() - except Exception as e: - label['text'] = f"Error: {e}" - -root = tk.Tk() -label = tk.Label(root, text="Enter something:") -label.pack() - -entry = tk.Entry(root) -entry.pack() - -button = tk.Button(root, text="Submit", command=on_click) -button.pack() - -label.pack() - -root.geometry("300x200") -root.mainloop() diff --git a/Python/Hard/73.py b/Python/Hard/73.py deleted file mode 100644 index a37ce9ca..00000000 --- a/Python/Hard/73.py +++ /dev/null @@ -1,25 +0,0 @@ -class Employee: - company_funds = 100000 - -def __init__(self, name, salary): - self.name = name - self.salary = salary - -def request_fund(self, amount): - if Employee.company_funds >= amount: - Employee.company_funds -= amount - self.salary += amount - else: - raise ValueError("Not enough funds in the company") - -def print_funds(): - print(f"Company funds left: {Employee.company_funds}") - -def main(): - emp1 = Employee("Alice", 50000) - emp2 = Employee("Bob", 45000) - - emp1.request_fund(60000) - emp2.request_fund(30000) - emp1.print_funds() -main() \ No newline at end of file diff --git a/Python/Hard/74.py b/Python/Hard/74.py deleted file mode 100644 index a4025589..00000000 --- a/Python/Hard/74.py +++ /dev/null @@ -1,13 +0,0 @@ -def filter_even_numbers(numbers): - try: - evens = [num for num in numbers if num % 2 == 0] - return evens - except TypeError as e: - print(f"TypeError: {e}") - -def main(): - numbers = [1, 2, 3, "four", 5, 6] - filtered_numbers = filter_even_numbers(numbers) - print(f"Filtered Numbers: {filtered_numbers}") - -main() diff --git a/Python/Hard/75.py b/Python/Hard/75.py deleted file mode 100644 index b2d65dd3..00000000 --- a/Python/Hard/75.py +++ /dev/null @@ -1,28 +0,0 @@ -import pandas as pd - -def create_pivot_table(df): - try: - pivot = pd.pivot_table(df, values='Sales', index='Product', columns='Region', aggfunc='sum') - return pivot - except KeyError as e: - print(f"KeyError: {e}") - -def main(): - data = { - 'Product': ['A', 'B', 'A', 'C', 'D', None], - 'Region': ['East', 'West', 'North', 'South', None, 'East'], - 'Sales': [100, 200, 150, None, 300, 250] - } - df = pd.DataFrame(data) - - pivot_table = create_pivot_table(df) - print(pivot_table) - - - try: - pivot_table = pd.pivot_table(df, values='NonExistentColumn', index='Product', columns='Region', aggfunc='sum') - except KeyError as e: - print(f"KeyError: {e}") - -main() - diff --git a/Python/Hard/76.py b/Python/Hard/76.py deleted file mode 100644 index b117b18b..00000000 --- a/Python/Hard/76.py +++ /dev/null @@ -1,30 +0,0 @@ -import pandas as pd - -def concatenate_dataframes(df1, df2): - try: - concatenated = pd.concat([df1, df2], axis=1) - return concatenated - except ValueError as e: - print(f"ValueError: {e}") - -def main(): - df1 = pd.DataFrame({ - 'A': [1, 2, 3], - 'B': [4, 5, 6] - }) - - df2 = pd.DataFrame({ - 'C': [7, 8], - 'D': [9, 10] - }) - - - concatenated_df = concatenate_dataframes(df1, df2) - print(concatenated_df) - - - df2 = df2.reindex(index=df1.index) - concatenated_df = concatenate_dataframes(df1, df2) - print(concatenated_df) - -main() diff --git a/Python/Hard/77.py b/Python/Hard/77.py deleted file mode 100644 index 7d8e4499..00000000 --- a/Python/Hard/77.py +++ /dev/null @@ -1,30 +0,0 @@ -import pandas as pd - -def resample_time_series(df): - try: - resampled = df.resample('M').mean() - return resampled - except TypeError as e: - print(f"TypeError: {e}") - -def main(): - data = { - 'Date': ['2022-01-01', '2022-02-01', '2022-03-01', '2022-04-01'], - 'Value': [100, 200, None, 400] - } - df = pd.DataFrame(data) - - try: - resampled_df = resample_time_series(df) - print(resampled_df) - except Exception as e: - print(f"Unexpected error: {e}") - - - df['Date'] = pd.to_datetime(df['Date']) - df.set_index('Date', inplace=True) - resampled_df = resample_time_series(df) - - print(resampled_df) - -main() diff --git a/Python/Hard/78.py b/Python/Hard/78.py deleted file mode 100644 index 22dd1e8f..00000000 --- a/Python/Hard/78.py +++ /dev/null @@ -1,18 +0,0 @@ -class Rectangle: - def __init__(self, width, height): - self.width = width - self.height = height - - def area(self): - return self.width * self.height - -def main(): - rect = Rectangle(5, 10) - try: - print(f"Area: {rect.area()}") - rect.width = -3 - print(f"Area after changing width: {rect.area()}") - except ValueError as e: - print(f"ValueError: {e}") - -main() diff --git a/Python/Hard/79.py b/Python/Hard/79.py deleted file mode 100644 index c0f784ac..00000000 --- a/Python/Hard/79.py +++ /dev/null @@ -1,18 +0,0 @@ -def update_inventory(inventory, item, quantity): - try: - if item in inventory: - inventory[item] += quantity - else: - inventory[item] = quantity - except TypeError as e: - print(f"TypeError: {e}") - -def main(): - inventory = {"apple": 10, "banana": 5} - update_inventory(inventory, "orange", 3) - print(f"Updated Inventory: {inventory}") - - update_inventory(inventory, "banana", "five") - print(f"Updated Inventory: {inventory}") - -main() diff --git a/Python/Hard/8.py b/Python/Hard/8.py deleted file mode 100644 index b1ef36ac..00000000 --- a/Python/Hard/8.py +++ /dev/null @@ -1,4 +0,0 @@ -list1 = [1, 2, 3] -list2 = [4, 5] -list1.extend(list2) -print(list1) diff --git a/Python/Hard/80.py b/Python/Hard/80.py deleted file mode 100644 index 5b21ccbe..00000000 --- a/Python/Hard/80.py +++ /dev/null @@ -1,17 +0,0 @@ -def reverse_words(sentence): - try: - words = sentence.split(" ") - reversed_words = words[::-1] - return "-".join(reversed_words) - except AttributeError as e: - print(f"AttributeError: {e}") - -def main(): - sentence = "Hello world this is Python" - reversed_sentence = reverse_words(sentence) - print(f"Reversed Sentence: {reversed_sentence}") - - sentence = None - reversed_sentence = reverse_words(sentence) - -main() diff --git a/Python/Hard/81.py b/Python/Hard/81.py deleted file mode 100644 index 2b8b9fc5..00000000 --- a/Python/Hard/81.py +++ /dev/null @@ -1,14 +0,0 @@ -def read_file(filename): - try: - file = open(filename, 'r') - content = file.read() - file.close() - return content - except FileNotFoundError as e: - print(f"FileNotFoundError: {e}") - -def main(): - content = read_file("example.txt") - print(f"File Content: {content}") - -main() diff --git a/Python/Hard/82.py b/Python/Hard/82.py deleted file mode 100644 index 13e3de0e..00000000 --- a/Python/Hard/82.py +++ /dev/null @@ -1,12 +0,0 @@ -def sort_by_length(words): - try: - return sorted(words, key=lambda x: len(x)) - except TypeError as e: - print(f"TypeError: {e}") - -def main(): - words = ["apple", "banana", "cherry", 1234, "grape"] - sorted_words = sort_by_length(words) - print(f"Sorted by length: {sorted_words}") - -main() diff --git a/Python/Hard/83.py b/Python/Hard/83.py deleted file mode 100644 index 53a78255..00000000 --- a/Python/Hard/83.py +++ /dev/null @@ -1,19 +0,0 @@ -from datetime import datetime - -def calculate_days_between(d1, d2): - try: - date_format = "%Y-%m-%d" - start = datetime.strptime(d1, date_format) - end = datetime.strptime(d2, date_format) - delta = end - start - return delta.days - except ValueError as e: - print(f"ValueError: {e}") - -def main(): - date1 = "2023-09-15" - date2 = "2023/09/20" - days_between = calculate_days_between(date1, date2) - print(f"Days between: {days_between}") - -main() diff --git a/Python/Hard/84.py b/Python/Hard/84.py deleted file mode 100644 index 7232a095..00000000 --- a/Python/Hard/84.py +++ /dev/null @@ -1,23 +0,0 @@ -from abc import ABC, abstractmethod - -class Animal(ABC): - @abstractmethod - def sound(self): - pass - -def sleep(self): - print("Sleeping...") - -class Dog(Animal): - def sound(self, volume): - print(f"Bark at volume {volume}") - -def main(): - try: - dog = Dog() - dog.sound() - dog.sleep() - except TypeError as e: - print(f"TypeError: {e}") - -main() \ No newline at end of file diff --git a/Python/Hard/85.py b/Python/Hard/85.py deleted file mode 100644 index f943e22b..00000000 --- a/Python/Hard/85.py +++ /dev/null @@ -1,17 +0,0 @@ -def countdown(n): - if n == 0: - print("Blast off!") - else: - print(n) - countdown(n - 1) - countdown(n - 2) - -def main(): - try: - countdown(5) - except RecursionError as e: - print(f"RecursionError: {e}") - - countdown(-1) - -main() diff --git a/Python/Hard/86.py b/Python/Hard/86.py deleted file mode 100644 index 62741c60..00000000 --- a/Python/Hard/86.py +++ /dev/null @@ -1,23 +0,0 @@ -from abc import ABC, abstractmethod - -class Animal(ABC): - @abstractmethod - def sound(self): - pass - - def sleep(self): - print("Sleeping...") - -class Dog(Animal): - def sound(self, volume): - print(f"Bark at volume {volume}") - -def main(): - try: - dog = Dog() - dog.sound() - dog.sleep() - except TypeError as e: - print(f"TypeError: {e}") - -main() diff --git a/Python/Hard/87.py b/Python/Hard/87.py deleted file mode 100644 index 41eeb884..00000000 --- a/Python/Hard/87.py +++ /dev/null @@ -1,34 +0,0 @@ -class Employee: - company_funds = 100000 - - def __init__(self, name, salary): - self.name = name - self.salary = salary - - def request_fund(self, amount): - if Employee.company_funds >= amount: - Employee.company_funds -= amount - self.salary += amount - else: - raise ValueError("Not enough funds in the company") - - def print_funds(self): - print(f"Company funds left: {Employee.company_funds}") - -def main(): - emp1 = Employee("Alice", 50000) - emp2 = Employee("Bob", 45000) - - try: - emp1.request_fund(60000) - except ValueError as e: - print(f"Error for {emp1.name}: {e}") - - try: - emp2.request_fund(30000) - except ValueError as e: - print(f"Error for {emp2.name}: {e}") - - emp1.print_funds() - -main() diff --git a/Python/Hard/88.py b/Python/Hard/88.py deleted file mode 100644 index c4f1eb18..00000000 --- a/Python/Hard/88.py +++ /dev/null @@ -1,15 +0,0 @@ -def custom_key(tup): - return tup[1] - -def sort_tuples(tuples_list): - try: - return sorted(tuples_list, key=custom_key) - except IndexError as e: - print(f"IndexError: {e}") - -def main(): - tuples_list = [(1, 2), (3,), (4, 5), (6,)] - sorted_list = sort_tuples(tuples_list) - print(sorted_list) - -main() diff --git a/Python/Hard/89.py b/Python/Hard/89.py deleted file mode 100644 index 2592b1d8..00000000 --- a/Python/Hard/89.py +++ /dev/null @@ -1,26 +0,0 @@ -def extract_nested_value(data, keys): - current = data - try: - for key in keys: - current = current[key] - return current - except KeyError: - print("Key not found in the dictionary") - except TypeError: - raise ValueError("Invalid key path") - -data = { - "level1": { - "level2": { - "level3": "value" - } - } -} - -keys = ["level1", "level4", "level3"] - -try: - result = extract_nested_value(data, keys) - print("Extracted Value:", result) -except ValueError as e: - print(f"ValueError: {e}") diff --git a/Python/Hard/9.py b/Python/Hard/9.py deleted file mode 100644 index c357bb0c..00000000 --- a/Python/Hard/9.py +++ /dev/null @@ -1,5 +0,0 @@ -list1 = [1, 2, 3] -list2 = list1 -list2.append(4) -print("list1:", list1) -print("list2:", list2) diff --git a/Python/Hard/90.py b/Python/Hard/90.py deleted file mode 100644 index 197610dd..00000000 --- a/Python/Hard/90.py +++ /dev/null @@ -1,15 +0,0 @@ -import numpy as np - -def add_arrays(arr1, arr2): - try: - return arr1 + arr2 - except ValueError as e: - print(f"ValueError: {e}") - -def main(): - arr1 = np.array([1, 2, 3]) - arr2 = np.array([[1], [2]]) - result = add_arrays(arr1, arr2) - print(f"Result: {result}") - -main() diff --git a/Python/Hard/91.py b/Python/Hard/91.py deleted file mode 100644 index 01f3601c..00000000 --- a/Python/Hard/91.py +++ /dev/null @@ -1,23 +0,0 @@ -def binary_search(arr, target, left, right): - if left > right: - return -1 - mid = (left + right) // 2 - if arr[mid] == target: - return mid - elif arr[mid] < target: - return binary_search(arr, target, mid + 1, right) - else: - return binary_search(arr, target, left, mid - 1) - -def main(): - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] - target = 10 - try: - index = binary_search(arr, target, 0, len(arr) - 1) - if index == -1: - raise ValueError("Target not found in the array") - print(f"Target found at index: {index}") - except ValueError as e: - print(f"ValueError: {e}") - -main() diff --git a/Python/Hard/92.py b/Python/Hard/92.py deleted file mode 100644 index d2e1674e..00000000 --- a/Python/Hard/92.py +++ /dev/null @@ -1,16 +0,0 @@ -def get_value(d, key): - try: - return d[key] - except KeyError: - return None - -def main(): - data = {"a": 1, "b": 2, "c": 3} - for key in ["a", "b", "d"]: - value = get_value(data, key) - if value is None: - print(f"Warning: Key '{key}' not found") - else: - print(f"Value for '{key}': {value}") - -main() diff --git a/Python/Hard/93.py b/Python/Hard/93.py deleted file mode 100644 index 12235f02..00000000 --- a/Python/Hard/93.py +++ /dev/null @@ -1,27 +0,0 @@ -import pandas as pd - -def create_pivot_table(df): - try: - pivot = pd.pivot_table(df, values='Sales', index='Product', columns='Region', aggfunc='sum') - return pivot - except KeyError as e: - print(f"KeyError: {e}") - -def main(): - data = { - 'Product': ['A', 'B', 'A', 'C', 'D', None], - 'Region': ['East', 'West', 'North', 'South', None, 'East'], - 'Sales': [100, 200, 150, None, 300, 250] - } - df = pd.DataFrame(data) - - pivot_table = create_pivot_table(df) - print(pivot_table) - - - try: - pivot_table = pd.pivot_table(df, values='NonExistentColumn', index='Product', columns='Region', aggfunc='sum') - except KeyError as e: - print(f"KeyError: {e}") - -main() diff --git a/Python/Hard/94.py b/Python/Hard/94.py deleted file mode 100644 index 16d347d2..00000000 --- a/Python/Hard/94.py +++ /dev/null @@ -1,21 +0,0 @@ -class A: - def greet(self): - print("Hello from A") - -class B: - def greet(self): - print("Hello from B") - -class C(A, B): - def greet(self): - super().greet() - -def main(): - c = C() - c.greet() - try: - A.greet() - except TypeError as e: - print(f"TypeError: {e}") - -main() diff --git a/Python/Hard/95.py b/Python/Hard/95.py deleted file mode 100644 index 9c79841d..00000000 --- a/Python/Hard/95.py +++ /dev/null @@ -1,14 +0,0 @@ -def countdown(n): - while n > 0: - yield n - n -= 1 - -async def main(): - try: - gen = countdown(5) - print(await gen.__next__()) - except StopIteration: - print("Countdown finished") - -import asyncio -asyncio.run(main()) \ No newline at end of file diff --git a/Python/Hard/96.py b/Python/Hard/96.py deleted file mode 100644 index b4151a55..00000000 --- a/Python/Hard/96.py +++ /dev/null @@ -1,18 +0,0 @@ -class Rectangle: - def __init__(self, width, height): - self.width = width - self.height = height - - def area(self): - return self.width * self.height - -def main(): - rect = Rectangle(5, 10) - try: - print(f"Area: {rect.area()}") - rect.width = -3 - print(f"Area after changing width: {rect.area()}") - except ValueError as e: - print(f"ValueError: {e}") - -main() diff --git a/Python/Hard/97.py b/Python/Hard/97.py deleted file mode 100644 index 591329e5..00000000 --- a/Python/Hard/97.py +++ /dev/null @@ -1,26 +0,0 @@ -def extract_nested_value(data, keys): - current = 0 - try: - for key in keys: - current = current[key] - return current - except KeyError: - print("Key not found in the dictionary") - except TypeError - raise ValueError("Invalid key path") - -data = { - "level1": { - "level2": { - "level3": "value" - } - } -} - -keys = ["level1", "level4", "level3"] - -try: - result = extract_nested_value(data, keys) - print("Extracted Value:", result) -except ValueError as e: - print(f"ValueError: {e}") \ No newline at end of file diff --git a/Python/Hard/98.py b/Python/Hard/98.py deleted file mode 100644 index 1b856071..00000000 --- a/Python/Hard/98.py +++ /dev/null @@ -1,33 +0,0 @@ -import random -import numpy as np - -class Reverse: - def __init__(self, data): - self.data = data - self.index = len(data) - - def __iter__(self): - return self - - def __next__(self): - if self.index <= 0: - raise StopIteration - self.index -= 1 - return self.data[self.index] - - def shuffle_data(self): - try: - self.data = list(np.random.shuffle(self.data)) - except Exception as e: - print("Shuffle error:", e) - -def main(): - rev = Reverse("Python") - rev.shuffle_data() - for char in rev: - print(char, end=" ") - - random_num = random.choice(rev.data) - print("\nRandom character from reversed data:", random_num) - -main() diff --git a/Python/Hard/99.py b/Python/Hard/99.py deleted file mode 100644 index 15e2813d..00000000 --- a/Python/Hard/99.py +++ /dev/null @@ -1,26 +0,0 @@ -import numpy as np -import random - -def modify_list(nested_list): - try: - for i in range(len(nested_list)): - nested_list[i][0] += random.randint(1, 5) - if np.mean(nested_list[i]) > 10: - print("Mean exceeds 10 for sublist:", nested_list[i]) - except TypeError as e: - print("Caught a TypeError:", e) - except IndexError: - print("Sublist is empty, cannot increment") - - return nested_list - -def main(): - nested_list = [[1, 2, 3], [], [4, 5], [6, 'x']] - modified_list = modify_list(nested_list) - for sublist in modified_list: - print(sublist) - - reshaped = np.reshape(nested_list, (2, 2)) - print("Reshaped list:", reshaped) - -main() diff --git a/Python/Hard/temp.txt b/Python/Hard/temp.txt deleted file mode 100644 index 8b137891..00000000 --- a/Python/Hard/temp.txt +++ /dev/null @@ -1 +0,0 @@ - From 000dee0adb41bf55219cad78c232d4fbe82a804d Mon Sep 17 00:00:00 2001 From: AdvikSaxena1 Date: Sat, 5 Oct 2024 11:54:18 +0530 Subject: [PATCH 40/62] Update 3.py --- Python/Easy/3.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Python/Easy/3.py b/Python/Easy/3.py index 6c1b8692..b6364ba9 100644 --- a/Python/Easy/3.py +++ b/Python/Easy/3.py @@ -1,10 +1,10 @@ -def greet() -print("Hello, world!") +def greet(): + print("Hello, world!") -def add(a, b) -return a + b +def add(a, b): + return a + b -class Car -def __init__(self, make, model): -self.make = make -self.model = model +class Car: + def __init__(self, make, model): + self.make = make + self.model = model From 0b2f3eb8a51bf4a2a5dfeb08107f1ea2cddc4cc4 Mon Sep 17 00:00:00 2001 From: Priyan Khandelwal Date: Sat, 5 Oct 2024 12:03:21 +0530 Subject: [PATCH 41/62] added a int data type to variable b --- C++/Easy/1 | Bin 0 -> 16832 bytes C++/Easy/1.cpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 C++/Easy/1 diff --git a/C++/Easy/1 b/C++/Easy/1 new file mode 100755 index 0000000000000000000000000000000000000000..5ba7cc230b67dbbacdd5eaa185a72475a4bd7ac4 GIT binary patch literal 16832 zcmeI4Pe>GT6vyBGF%`A7CCbQPE=8sIFRjIjo&IbpMan9&DEUL(k)6`DbVZF7_mG4J zX+a&jbdmH>VIq-1upNpHk=UUy!c&DI5qan!mAyAJTQeC29pgRt&ilRJpEvLK*}1-* zS^n@X9l!=?cGNmlmIGh_Bpd;3LY1S0s5(&QtMmCQY1V4mVe8bYi1I9;gsAZaYOKrJ zdD%J#Mx2DxB&v-}h=|e?(Z_mh%@_0Pm)UM?p*V3?n{qN{MKxT|bHMz5LS;|4r(W{$-Gu}s>C`#k7&8L@P)u#MlZ)*@^vdt)}!`t8( zmir2auBiU$K6iI>5za{{{Z1|%xwJ8UTHr{ockV>5-48t({$4T4L%)~V=)H7bTGQ^J zq$E?;AGKgT%{e)Fg?U(%+N9O#G4F>m{CuqYt9v^mN?YDR;|T5s*oLBdLNY)K`W;40 ze95+;XnjIPuU`ryHYUIXm;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@G zCcp%k025#WOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@G zCcp&#Cju*nV7A;A^DnqyIz&DVrk`Z!9=oCaxPB?_5HG0ZINP|m*;7w6^-Rm?Nz|WC zCTq{159+&4$3EyxtqU82Oue0&c1S4du_lq3+ned!Z_OsaO$$_j17iI+5^W)&^eD|; z5k-WQ#-P#xscnsF7&5R%+(1U#T{h~Z*59*1i}gFudnN3^U!6v1Y3R)Ie0m&DQd@eW z%=I`&X_vw7q!-Y*4i!L=VgI*0A=$OoaDC>_&%|E`*b3p@qff&lM~d(7zdP)?UaH>l ze7#uoJoV|`Xx6j&^WK@HTm3gD1MQFBx5S+^P{cXLW z;M~~a#Ngcc3CHWXeI*}9t8Y&Yc<=Q+94+~BvUcgl=l;mX-B&NW_efi#*Xldno;PRK Slva04<_=|#zO7wa1o#e-yv+Xq literal 0 HcmV?d00001 diff --git a/C++/Easy/1.cpp b/C++/Easy/1.cpp index 7714bf2e..d617c855 100644 --- a/C++/Easy/1.cpp +++ b/C++/Easy/1.cpp @@ -3,7 +3,7 @@ using namespace std; int main() { const int a = 10; - b = 11; + int b = 11; b = 110; } From 6c987d1141220ec202e02f6bbdc41511ef5591a9 Mon Sep 17 00:00:00 2001 From: yashrajrohit Date: Sat, 5 Oct 2024 12:03:56 +0530 Subject: [PATCH 42/62] Update 1.py --- Python/Easy/1.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Python/Easy/1.py b/Python/Easy/1.py index d80b073d..55fc210f 100644 --- a/Python/Easy/1.py +++ b/Python/Easy/1.py @@ -1,9 +1,10 @@ -If x==10 +x = int(input("enter a number ")) +y = int(input("enter a number ")) +if x==10: print(x) -—------------------ -if y > 5 +if y > 5: print(y) -for i in range(5) +for i in range(5): print(i) From dcb33bc26599f458e7492d9c7cab9b5423af38ca Mon Sep 17 00:00:00 2001 From: ShreyasAndurlekar Date: Sat, 5 Oct 2024 12:08:00 +0530 Subject: [PATCH 43/62] solved 1 --- C++/Medium/1.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/C++/Medium/1.cpp b/C++/Medium/1.cpp index 1c6e5b61..48f3687b 100644 --- a/C++/Medium/1.cpp +++ b/C++/Medium/1.cpp @@ -1,7 +1,11 @@ #include #include + int main() { - std::string cars = {"Mercedes", "Audi", "Maruti", "Honda", "Ford"} std::cout << cars[0][] << std::endl; + std::string cars[5] = {"Mercedes", "Audi", "Maruti", "Honda", "Ford"}; + std::cout << cars[0] << std::endl; + + // string was not an array return 0; } From 0c9ff2a3bc5d1eaecba61f5762821a8ca011723e Mon Sep 17 00:00:00 2001 From: ShreyasAndurlekar Date: Sat, 5 Oct 2024 12:08:35 +0530 Subject: [PATCH 44/62] solve hogya --- C++/Medium/a.out | Bin 0 -> 19448 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 C++/Medium/a.out diff --git a/C++/Medium/a.out b/C++/Medium/a.out new file mode 100755 index 0000000000000000000000000000000000000000..bbb701c806013d90040e6b82dcbb1bd1308cb64a GIT binary patch literal 19448 zcmeHPe{dYteSas(wjjom0fVs_d@(;_*Z9y$vXIF*oGhKZ3K9tYm=J=qobFE2!Rb!i z?b#BA)F3;a5B+cXpOaQJ~PL&nHN<}XRB)zqCQUqRTk_AKdkRa)~mFg;!!%$S4 zIO#2;Q-wQWRyoFy`Br^iQbzI0UklbL{~6l#C^l=in(}LR6hfi&0^Ato7ln)THYvSL zN{?Z+iYG&kCz+w6QQ39E8t|wvbm|Q%Jtu52)dWMTgG%>nMx>PbI+fndUTH=+;eL}W z7;=5rLyzL}Q44o-m#WXLA7)iN8B%{!xgs9xYpA~>9@!d?B{CyhM;aTpHq`slNnfqx zlV4sOG^Tc4+bdvZifAf~qHLduvpwRStN0}UrLVvBkUl;A-pT%hZ#GKh3Iob_4n=AzvinenLUMTcvsB+Iu}1b?&9Z#F7-xSHhC|_)F&Z3#k!~XnZ{6JQ0;A4s zX%bD1hKAaD^qv|$h$eJh;~tOhdcAv_-s9JUL0LzAG!cmxt0w4PLqmx{^4C%ulL`2n z2^(#QcQCl8NAGUbyN%kK{$y%zC>7CT==hM4M2Ce2WGs_$^iFG6cd}bIeXjM#l4%`{ zkLtJ|r$VVwJ(h?WduTL`jOfGBR63am#Sut-PYs#4=Jbb$)uFIj%7EBTO+~jD(O}mQ zb*Fomxb|_2KUiYz7~CCtI%??gXkx$^l;f!c2mCcK6N#mVlj*2*rQ4_vCo@KA&5=&U zli^U@yi}-d7{%Ll-55+I_v-QF0Iu6;DwRxOXp~q-t=<$z9r|Dlw~=N)uE(xxy6Z4t zdlP$OiHP16O=pI1Gof2f_*Pu|x9a_&SX^LCB37VdMA6NI?ngtR7*WC_A-z9F1M2pu z06T3&!dte`L%)I0fiUC=^Ai>}>ARYn^*UdTXujcwrk!oN-&ZGgwYTjA3Ua-#uC@TJ z_1jVNT(9-jTW59o(^}s)x`&ow4p4!=a?CXd(wPaD1FjI2c>bS(GY|eMAnlQJ2Ev}e zy_=sWotKS%OhE2mK%+vk-&g!j;Q#m+w_++&DPC5zoeN*VlVyc?Q{lHsyh6OMaAWg* zm_n9|Gv%b3?3Ih>6_4zn8;hMqGnDhdCm;Um-up3KSth&+&#a4`L2cWj^m%^F^HT3Q zWJL(Cn*TC=Mm?k|1CkAo6;$~2)h14JBc2lx<&=$%hFN9CMwjy`#hJCy?a#$|8-0ys zMTi9({X84JI$$F77+h_m^Yf9Kzs^SQRCZQ?#*a>7-(aKT5o?v3ZFGd+DuXt<3bEu3 z+vrpWmk}GCV@kYzHaa@YD)-pvXIfMtCT(;KIIDcsMqg=Bg*arRW58JDu#LXTq6%@u zMpv(Tl6%xfS3^hAr)+eZe{*@pMpsi9X8pf{zo@$CJ#FmGN^N}E%U1}Y9hfr8a?{$_ zQ32ndoNB+lF`xm>P)QsOjF=U&X?bb-x1na63s&V4_R(?Fej zD38+sox3lO(}g&9cOIvKI+x1hG(hM2@;D95xvo4;19EO>9;bmgSDVLa0M2d9<23N* z&d%dB;O5HmI1RM9cRu9y<}SV8Cq#eMh87{?k-K!c1OE_j?{@yL9Qa!f{B;NZ9}fH_ z2mYJ`KkmT))`36fz#nzs-*({Nbl~?p@INWQ{Xc8VzVLZ1`-(R9>U?KU&_CsWR-4%I z_lR0<%^yPa-F{!yhW$V>z$SJ)2#Pkb>}v$JFBoeu^gd7L7 zzwH(Rn?KaD^V$<{U9CN_P_B87YcG6goC^b6m4V9Kj2U;4jcXZ&OdVcGsKFz)VCN zuefxRv==<(pK70YxCWAcL&Lj0`?5B1;1fW#?14=Hlam(yBwBwEV^GT;*Rs#g{v|G# zj*0jsUTy3RPl3>|Db${Qd-foN+Qyz%(UhN}wr7vY`#BAB)P_#F69Ej)YFW6aTznB$CT(7IL$HzD(z2Op zE!+EyHoluG2YzC918i#9CxAYqWuMft&r!F3nuud}PK!(xhSIli?Tf6P*gwOi=$)OvN3yAn%Ntk~pTo%q(Ii`>Abm3e zbrklFAW(;${Wu;3837m%9tJ!$i4$r*E)EJNg#pKw;LIctL>b4}Le-wDwTTYGj{XoK zK_q2(c2O|1PZC*OmkrLq)( zr3frVU?~Di5m<`A?>Yh=tie&~h^E5PNHi^)GLe|*2&FPcOlZkOBqUmssfe(DYPrg5 zE$zpW32%QYIpj@b;&E>*?M);N?;b3mMubQ1D)6i?|0KQn(JS=S+qoP~g{S9pxf#G2 zzy*Ro&*csQKKo8CH;lD}58ln?=)2L%U*>W(fI9&n06YTtIN&M39|P|DRW4Tn_rDEz z3E*RZ^nP;^FalWi>s;<0Kq|cUsPL*oP-Uc(;kCH_;48swydD#N^uE} zdOCs6j1;w{oAjdfoOvsJmn%u}S|X9J3@x1XYM`;Ftm3zK}#@V0)=7MPMlcOA%O#z)}R3BCr&Jr3n0=ivaIG;Qa2WNq-rSB?@@tZ zzblnK?uKk+Il@k5G_73KoIboRIS!~3zF zCTrA7U_il61#ebxSiyY?PAYgv!6OPzDLAd*jDqtD@@A51wW-8w-(2E!>LcKlfkGi{ zYr4w2skbkaFfv|$ov+qcv$eJ^Bk}spic+XjfKfMBh@a;Qh(M^{Y46cN)p1@WKzlZd z$BZp@=Ue-XBoRM%;GlZ> zKEU*QaN-f?S=TMozk`!v{?lhnk2qW0=rtv|-Wf&zoP&N21W5iSCmr&|?6*q!b4BIF z5O9=Y@;%albF6*$tTG_&tQF32JuK-LSoZ;z|03wL|982%@T(N#TcB5CN7LE>OPa6& z9q*-`P7eAbkYA1Vf+>r-eTpA~UTlByM%;)tnxX~2J3w~~1;9{p6 z0V!tx4x*Q>7W_OhtqE~A=v42F+Jq+8TfqFDi=7in-sxum&xvC7-tR(x9dxR9w|bE9 zcvyx9Q87Cspp$&H@^h1Fz*QJ0XM-M4N|!16l#88zccEW}2T(ElcPsis%1^oOg*qMq zy_lcxyU=gIQ>mDIn&@SC=<$78`9BIejVtGMalpmSDUvU;kNz#tsa=gKZikiqdc=*c zI}uO>1)3y%y||&NklqS9*>PUK5hWjR*ck@BSbHCEp+BzdJN+!fM8sR@io`Agy_o%N zF7$gqC;#KBALUvpEPdC-{!thDi^`7ky4Em{DCUpo4yO#iFNxj4p}v^hxeh|w$n^L7 z!Xls0pc_Mam{Jodep$q=eimlf<|;8iXHb!GZ{jU zrS(iA9UDkQBW<_HOabg3|L7`1r>`IQ%6t_UfV*sAUd+0^q{7QT1%JETRwYj zQ%75~(08?8x3j5Tzpk~lJBYl8rk(9Um6YJ$rt695UOhzHz$uRa$sXoL`Y0u6AdTcY zZ10Z55_%>bjg-90{InAp3bv64ks&oFJ7d(CMWrIY$# z2zegZ_kLq3i3q2kxDmXzLEn`@I!8-wsW}YPY4(QruuJ~;?mlG@AZ13he8!iG_WRrt zOin+)WKo93;-G$gJuK#EDIw>@O8n^zFSds~r8?X$(`FV^C}HSPeAdh$%O_%Hv;2-z zwibI-LJM&<+j3;ABqMv8mAxJsS|yC{f=cpK5ZZ{u@*plu9f5U!{Zn zb{gQ4e7MNCBTdQV%hVwGbjRh497%p)mefxLDPD`}r$-QFeAyYL4Txrc8}2{BAo@UM zWXUWrGu299E~B2sMW5fYhxNX6n#JLlTNa?*RZ6rfcFzvj^0G=A-p#en*8HZ-)q>o! z0Oy94RB>TmVL@Bv^AVS-GvBpf^cTsub;+qMX*8X7hG%}FP8<9Wp|F zfJVxMgM3C4-_)@1VSh^0hli(cIF&^Ds4;3I^<`qn_s7;1Qwr&PTPZVDiVud;gTfaX zO`r-B8Yz>r2T7>d22+6O;H9GR5Gkm$;kY4ul)Nf@IQ0!A)k!)U7Cs|70+c5FkWR|k zt1mjJruc&qSYr&;APX@%5{?cVc>ADqX=&A*{hK!U9F>QLVlZzS#6=~1c0^097N`FqP-&@}^?9A1A@5tFHd35f zpV!M{pkc|#(&u%5hP=)X5n0HFz1#+b*3h|rUN>jR@6+r*%Q5@{^l43=abA~actll3 z{*#~VzaonXoKT;zK7S`*$lnRLe%9yqe?{r$TAcb1f<_{2A4>^l zQINmKDC(mAe*g@-zE|lnlzYZl8PH)~e8-_*qt@>kvOJq$oZ%6Nen9Cnl+Lj-AnP&w zfm2^Cb_5jsq!k#`2st!3T43k$M}zMLh)z) zo4qE7;eHdfex29xTr^5dWNtDsL^%=*0U&;NIb|GyAjzf@R{ z$H60@QJYwwzY{iILDE7zV*=}!^%>HBJ-faLDA5`d@^#JzSda0GpiDHbKM*iEYgwO+ z+e*N8PNx^E`jxoFW&O)6ih083?9eepq+mc9oLAQmt^3mwCHv3qIs-KJT`H=dnk&td b2h?{==5f7@)8$@F{~vam5|=v^9H{tjuY(sa literal 0 HcmV?d00001 From 907c71e58daacc28e6941a4737d8201fb3b27b21 Mon Sep 17 00:00:00 2001 From: Miqdadmemon Date: Sat, 5 Oct 2024 12:26:20 +0530 Subject: [PATCH 45/62] java Question 2 easy --- Java/Easy/2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/2.java b/Java/Easy/2.java index 11befc8a..e8c88fec 100644 --- a/Java/Easy/2.java +++ b/Java/Easy/2.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); + System.out.println(numbers[0]); } } From 3e936cb8aab0f2c335422450b1222fe3032a5335 Mon Sep 17 00:00:00 2001 From: Tushar Nadavadekar <143600822+TokiG0@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:00:46 +0530 Subject: [PATCH 46/62] solved-java-easy-11 Hack o' Holics java/easy/java-11 --- Java/Easy/11.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/11.java b/Java/Easy/11.java index d96b2487..7ef59249 100644 --- a/Java/Easy/11.java +++ b/Java/Easy/11.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { - boolean isValid = True; + boolean isValid = true ; System.out.println(isValid); } } From b9852c5462b750882c61bcd7302f7f3dbc5c1046 Mon Sep 17 00:00:00 2001 From: ayushyadav092005 Date: Sat, 5 Oct 2024 13:17:49 +0530 Subject: [PATCH 47/62] Update 45.java --- Java/Easy/45.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/45.java b/Java/Easy/45.java index df46fd4d..8e5c132e 100644 --- a/Java/Easy/45.java +++ b/Java/Easy/45.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { - double x = 5.0 / 0; + double x = 5.0 / 1.0; System.out.println(x); } } From f68745587b64b56c02c0c4560a92e22224f5b5f8 Mon Sep 17 00:00:00 2001 From: Jatin Pathak Date: Sat, 5 Oct 2024 13:19:13 +0530 Subject: [PATCH 48/62] 66-java-easy --- Java/Easy/66.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/66.java b/Java/Easy/66.java index 77f4fd8c..1440d9e1 100644 --- a/Java/Easy/66.java +++ b/Java/Easy/66.java @@ -1,7 +1,7 @@ class Main { public static void main(String[] args) { int a = 5; - int b = '10'; + int b = 10; System.out.println(a + b); } } From 45530af8ca60a5494f1832625b7cd29bee38ddc7 Mon Sep 17 00:00:00 2001 From: Harsh Seth Date: Sat, 5 Oct 2024 13:19:19 +0530 Subject: [PATCH 49/62] Update 25.c CluelessCoders prob 25 using C lang --- C/Easy/25.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/C/Easy/25.c b/C/Easy/25.c index 7b69e8eb..897f8699 100644 --- a/C/Easy/25.c +++ b/C/Easy/25.c @@ -1,7 +1,8 @@ #include +#include int main() { - int x = "hello"; + int x[] = "hello"; printf("%d", x); return 0; } From 483ee67bde5b2698fd3042dfad819a52aac1f912 Mon Sep 17 00:00:00 2001 From: sanjeev Date: Sat, 5 Oct 2024 13:19:51 +0530 Subject: [PATCH 50/62] 8.java --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ Java/Easy/8.java | 3 +- 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..cea4d3f4 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..7c072509 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/Hp/OneDrive/Documents/GitHub/Hacktober-Fest/C/Easy", + "program": "c:/Users/Hp/OneDrive/Documents/GitHub/Hacktober-Fest/C/Easy/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..bb879da5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/Java/Easy/8.java b/Java/Easy/8.java index ca8957da..713afb66 100644 --- a/Java/Easy/8.java +++ b/Java/Easy/8.java @@ -1,7 +1,8 @@ class Main { public static void main(String[] args) { int a = 5; - double result = Math.pow(a); + int b = 2; + double result = Math.pow(a,b); System.out.println(result); } } From 5022bef763dd1284ccb1f18525dc72b3a574ecf7 Mon Sep 17 00:00:00 2001 From: Varun Raj <140655393+itsnotcloud@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:20:44 +0530 Subject: [PATCH 51/62] Update 140.java Java Easy 140 --- Java/Easy/140.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/140.java b/Java/Easy/140.java index 80ca4739..7ab433d4 100644 --- a/Java/Easy/140.java +++ b/Java/Easy/140.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { - int x = 5 / 0; + int x = 5 / 1; System.out.println(x); } } From 3b4eda664406e4b0039d347873e8d0dc689fe119 Mon Sep 17 00:00:00 2001 From: Harsh Seth Date: Sat, 5 Oct 2024 13:21:28 +0530 Subject: [PATCH 52/62] Update 25.c CluelessCoders 25 using C lang --- C/Easy/25.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/C/Easy/25.c b/C/Easy/25.c index 897f8699..bceeb3cf 100644 --- a/C/Easy/25.c +++ b/C/Easy/25.c @@ -2,7 +2,7 @@ #include int main() { - int x[] = "hello"; - printf("%d", x); + char x[] = "hello"; + printf("%s", x); return 0; } From 79f678380b52db1905e11005b24673e000357e91 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Sat, 5 Oct 2024 13:25:16 +0530 Subject: [PATCH 53/62] Revert "Merabranch" --- C++/Medium/1.cpp | 6 +----- C++/Medium/a.out | Bin 19448 -> 0 bytes 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100755 C++/Medium/a.out diff --git a/C++/Medium/1.cpp b/C++/Medium/1.cpp index 48f3687b..1c6e5b61 100644 --- a/C++/Medium/1.cpp +++ b/C++/Medium/1.cpp @@ -1,11 +1,7 @@ #include #include - int main() { - std::string cars[5] = {"Mercedes", "Audi", "Maruti", "Honda", "Ford"}; - std::cout << cars[0] << std::endl; - - // string was not an array + std::string cars = {"Mercedes", "Audi", "Maruti", "Honda", "Ford"} std::cout << cars[0][] << std::endl; return 0; } diff --git a/C++/Medium/a.out b/C++/Medium/a.out deleted file mode 100755 index bbb701c806013d90040e6b82dcbb1bd1308cb64a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19448 zcmeHPe{dYteSas(wjjom0fVs_d@(;_*Z9y$vXIF*oGhKZ3K9tYm=J=qobFE2!Rb!i z?b#BA)F3;a5B+cXpOaQJ~PL&nHN<}XRB)zqCQUqRTk_AKdkRa)~mFg;!!%$S4 zIO#2;Q-wQWRyoFy`Br^iQbzI0UklbL{~6l#C^l=in(}LR6hfi&0^Ato7ln)THYvSL zN{?Z+iYG&kCz+w6QQ39E8t|wvbm|Q%Jtu52)dWMTgG%>nMx>PbI+fndUTH=+;eL}W z7;=5rLyzL}Q44o-m#WXLA7)iN8B%{!xgs9xYpA~>9@!d?B{CyhM;aTpHq`slNnfqx zlV4sOG^Tc4+bdvZifAf~qHLduvpwRStN0}UrLVvBkUl;A-pT%hZ#GKh3Iob_4n=AzvinenLUMTcvsB+Iu}1b?&9Z#F7-xSHhC|_)F&Z3#k!~XnZ{6JQ0;A4s zX%bD1hKAaD^qv|$h$eJh;~tOhdcAv_-s9JUL0LzAG!cmxt0w4PLqmx{^4C%ulL`2n z2^(#QcQCl8NAGUbyN%kK{$y%zC>7CT==hM4M2Ce2WGs_$^iFG6cd}bIeXjM#l4%`{ zkLtJ|r$VVwJ(h?WduTL`jOfGBR63am#Sut-PYs#4=Jbb$)uFIj%7EBTO+~jD(O}mQ zb*Fomxb|_2KUiYz7~CCtI%??gXkx$^l;f!c2mCcK6N#mVlj*2*rQ4_vCo@KA&5=&U zli^U@yi}-d7{%Ll-55+I_v-QF0Iu6;DwRxOXp~q-t=<$z9r|Dlw~=N)uE(xxy6Z4t zdlP$OiHP16O=pI1Gof2f_*Pu|x9a_&SX^LCB37VdMA6NI?ngtR7*WC_A-z9F1M2pu z06T3&!dte`L%)I0fiUC=^Ai>}>ARYn^*UdTXujcwrk!oN-&ZGgwYTjA3Ua-#uC@TJ z_1jVNT(9-jTW59o(^}s)x`&ow4p4!=a?CXd(wPaD1FjI2c>bS(GY|eMAnlQJ2Ev}e zy_=sWotKS%OhE2mK%+vk-&g!j;Q#m+w_++&DPC5zoeN*VlVyc?Q{lHsyh6OMaAWg* zm_n9|Gv%b3?3Ih>6_4zn8;hMqGnDhdCm;Um-up3KSth&+&#a4`L2cWj^m%^F^HT3Q zWJL(Cn*TC=Mm?k|1CkAo6;$~2)h14JBc2lx<&=$%hFN9CMwjy`#hJCy?a#$|8-0ys zMTi9({X84JI$$F77+h_m^Yf9Kzs^SQRCZQ?#*a>7-(aKT5o?v3ZFGd+DuXt<3bEu3 z+vrpWmk}GCV@kYzHaa@YD)-pvXIfMtCT(;KIIDcsMqg=Bg*arRW58JDu#LXTq6%@u zMpv(Tl6%xfS3^hAr)+eZe{*@pMpsi9X8pf{zo@$CJ#FmGN^N}E%U1}Y9hfr8a?{$_ zQ32ndoNB+lF`xm>P)QsOjF=U&X?bb-x1na63s&V4_R(?Fej zD38+sox3lO(}g&9cOIvKI+x1hG(hM2@;D95xvo4;19EO>9;bmgSDVLa0M2d9<23N* z&d%dB;O5HmI1RM9cRu9y<}SV8Cq#eMh87{?k-K!c1OE_j?{@yL9Qa!f{B;NZ9}fH_ z2mYJ`KkmT))`36fz#nzs-*({Nbl~?p@INWQ{Xc8VzVLZ1`-(R9>U?KU&_CsWR-4%I z_lR0<%^yPa-F{!yhW$V>z$SJ)2#Pkb>}v$JFBoeu^gd7L7 zzwH(Rn?KaD^V$<{U9CN_P_B87YcG6goC^b6m4V9Kj2U;4jcXZ&OdVcGsKFz)VCN zuefxRv==<(pK70YxCWAcL&Lj0`?5B1;1fW#?14=Hlam(yBwBwEV^GT;*Rs#g{v|G# zj*0jsUTy3RPl3>|Db${Qd-foN+Qyz%(UhN}wr7vY`#BAB)P_#F69Ej)YFW6aTznB$CT(7IL$HzD(z2Op zE!+EyHoluG2YzC918i#9CxAYqWuMft&r!F3nuud}PK!(xhSIli?Tf6P*gwOi=$)OvN3yAn%Ntk~pTo%q(Ii`>Abm3e zbrklFAW(;${Wu;3837m%9tJ!$i4$r*E)EJNg#pKw;LIctL>b4}Le-wDwTTYGj{XoK zK_q2(c2O|1PZC*OmkrLq)( zr3frVU?~Di5m<`A?>Yh=tie&~h^E5PNHi^)GLe|*2&FPcOlZkOBqUmssfe(DYPrg5 zE$zpW32%QYIpj@b;&E>*?M);N?;b3mMubQ1D)6i?|0KQn(JS=S+qoP~g{S9pxf#G2 zzy*Ro&*csQKKo8CH;lD}58ln?=)2L%U*>W(fI9&n06YTtIN&M39|P|DRW4Tn_rDEz z3E*RZ^nP;^FalWi>s;<0Kq|cUsPL*oP-Uc(;kCH_;48swydD#N^uE} zdOCs6j1;w{oAjdfoOvsJmn%u}S|X9J3@x1XYM`;Ftm3zK}#@V0)=7MPMlcOA%O#z)}R3BCr&Jr3n0=ivaIG;Qa2WNq-rSB?@@tZ zzblnK?uKk+Il@k5G_73KoIboRIS!~3zF zCTrA7U_il61#ebxSiyY?PAYgv!6OPzDLAd*jDqtD@@A51wW-8w-(2E!>LcKlfkGi{ zYr4w2skbkaFfv|$ov+qcv$eJ^Bk}spic+XjfKfMBh@a;Qh(M^{Y46cN)p1@WKzlZd z$BZp@=Ue-XBoRM%;GlZ> zKEU*QaN-f?S=TMozk`!v{?lhnk2qW0=rtv|-Wf&zoP&N21W5iSCmr&|?6*q!b4BIF z5O9=Y@;%albF6*$tTG_&tQF32JuK-LSoZ;z|03wL|982%@T(N#TcB5CN7LE>OPa6& z9q*-`P7eAbkYA1Vf+>r-eTpA~UTlByM%;)tnxX~2J3w~~1;9{p6 z0V!tx4x*Q>7W_OhtqE~A=v42F+Jq+8TfqFDi=7in-sxum&xvC7-tR(x9dxR9w|bE9 zcvyx9Q87Cspp$&H@^h1Fz*QJ0XM-M4N|!16l#88zccEW}2T(ElcPsis%1^oOg*qMq zy_lcxyU=gIQ>mDIn&@SC=<$78`9BIejVtGMalpmSDUvU;kNz#tsa=gKZikiqdc=*c zI}uO>1)3y%y||&NklqS9*>PUK5hWjR*ck@BSbHCEp+BzdJN+!fM8sR@io`Agy_o%N zF7$gqC;#KBALUvpEPdC-{!thDi^`7ky4Em{DCUpo4yO#iFNxj4p}v^hxeh|w$n^L7 z!Xls0pc_Mam{Jodep$q=eimlf<|;8iXHb!GZ{jU zrS(iA9UDkQBW<_HOabg3|L7`1r>`IQ%6t_UfV*sAUd+0^q{7QT1%JETRwYj zQ%75~(08?8x3j5Tzpk~lJBYl8rk(9Um6YJ$rt695UOhzHz$uRa$sXoL`Y0u6AdTcY zZ10Z55_%>bjg-90{InAp3bv64ks&oFJ7d(CMWrIY$# z2zegZ_kLq3i3q2kxDmXzLEn`@I!8-wsW}YPY4(QruuJ~;?mlG@AZ13he8!iG_WRrt zOin+)WKo93;-G$gJuK#EDIw>@O8n^zFSds~r8?X$(`FV^C}HSPeAdh$%O_%Hv;2-z zwibI-LJM&<+j3;ABqMv8mAxJsS|yC{f=cpK5ZZ{u@*plu9f5U!{Zn zb{gQ4e7MNCBTdQV%hVwGbjRh497%p)mefxLDPD`}r$-QFeAyYL4Txrc8}2{BAo@UM zWXUWrGu299E~B2sMW5fYhxNX6n#JLlTNa?*RZ6rfcFzvj^0G=A-p#en*8HZ-)q>o! z0Oy94RB>TmVL@Bv^AVS-GvBpf^cTsub;+qMX*8X7hG%}FP8<9Wp|F zfJVxMgM3C4-_)@1VSh^0hli(cIF&^Ds4;3I^<`qn_s7;1Qwr&PTPZVDiVud;gTfaX zO`r-B8Yz>r2T7>d22+6O;H9GR5Gkm$;kY4ul)Nf@IQ0!A)k!)U7Cs|70+c5FkWR|k zt1mjJruc&qSYr&;APX@%5{?cVc>ADqX=&A*{hK!U9F>QLVlZzS#6=~1c0^097N`FqP-&@}^?9A1A@5tFHd35f zpV!M{pkc|#(&u%5hP=)X5n0HFz1#+b*3h|rUN>jR@6+r*%Q5@{^l43=abA~actll3 z{*#~VzaonXoKT;zK7S`*$lnRLe%9yqe?{r$TAcb1f<_{2A4>^l zQINmKDC(mAe*g@-zE|lnlzYZl8PH)~e8-_*qt@>kvOJq$oZ%6Nen9Cnl+Lj-AnP&w zfm2^Cb_5jsq!k#`2st!3T43k$M}zMLh)z) zo4qE7;eHdfex29xTr^5dWNtDsL^%=*0U&;NIb|GyAjzf@R{ z$H60@QJYwwzY{iILDE7zV*=}!^%>HBJ-faLDA5`d@^#JzSda0GpiDHbKM*iEYgwO+ z+e*N8PNx^E`jxoFW&O)6ih083?9eepq+mc9oLAQmt^3mwCHv3qIs-KJT`H=dnk&td b2h?{==5f7@)8$@F{~vam5|=v^9H{tjuY(sa From 61145b58259c8adf1f5128d4c45faf786dbdae47 Mon Sep 17 00:00:00 2001 From: ayushyadav092005 Date: Sat, 5 Oct 2024 13:27:36 +0530 Subject: [PATCH 54/62] Update 52.java --- Java/Easy/52.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/52.java b/Java/Easy/52.java index bcbe4aa5..a9ee81fc 100644 --- a/Java/Easy/52.java +++ b/Java/Easy/52.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { int a = 10; - String s = 'Hello'; + String s = "Hello"; } } From 946a59c9584968a91171a78c937058db851b84de Mon Sep 17 00:00:00 2001 From: ayushyadav092005 Date: Sat, 5 Oct 2024 13:29:19 +0530 Subject: [PATCH 55/62] Update 53.java --- Java/Easy/53.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/53.java b/Java/Easy/53.java index df06d34c..5e862589 100644 --- a/Java/Easy/53.java +++ b/Java/Easy/53.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { int[] arr = new int[5]; - arr[5] = 10; + arr[0] = 10; } } From ef80baa4dddad271eebfc0d82f804ea39f898e91 Mon Sep 17 00:00:00 2001 From: Tushar Nadavadekar Date: Sat, 5 Oct 2024 13:33:44 +0530 Subject: [PATCH 56/62] solved-java-easy-13 Hack o' Holics java/easy/java-13 --- Java/Easy/13.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Java/Easy/13.java b/Java/Easy/13.java index a8af40fa..b1205d2b 100644 --- a/Java/Easy/13.java +++ b/Java/Easy/13.java @@ -1,7 +1,7 @@ class Main { public static void main(String[] args) { - int a = 10; - Integer b = null; + String a = "10"; + String b = null; System.out.println(a.equals(b)); } } From 6e8c027ae753c30f165f63ac992eb717a7b522ee Mon Sep 17 00:00:00 2001 From: Varun Raj <140655393+itsnotcloud@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:36:15 +0530 Subject: [PATCH 57/62] Update 144.java Java Easy 144 --- Java/Easy/144.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/144.java b/Java/Easy/144.java index be674e14..7a948054 100644 --- a/Java/Easy/144.java +++ b/Java/Easy/144.java @@ -1,7 +1,7 @@ class Main { public static void main(String[] args) { int a = 10; - double result = a / 0; + double result = a / 1; System.out.println(result); } } From c01a7a8b1ed1c5f3bf10035ce19b0a7f96752821 Mon Sep 17 00:00:00 2001 From: Xstroke1820 Date: Sat, 5 Oct 2024 13:36:26 +0530 Subject: [PATCH 58/62] Update 39.java java easy q39 --- Java/Easy/39.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/39.java b/Java/Easy/39.java index f66a8dbb..7923e479 100644 --- a/Java/Easy/39.java +++ b/Java/Easy/39.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { - int x = Math.pow(2, 3); + double x = Math.pow(2,3); System.out.println(x); } } From 062c45208a3a547bdae3ef8ad51befd6d96aba46 Mon Sep 17 00:00:00 2001 From: ERROR404 Date: Sat, 5 Oct 2024 13:37:20 +0530 Subject: [PATCH 59/62] 9 c --- C/Easy/9.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/C/Easy/9.c b/C/Easy/9.c index ca3c624c..02d4e3d4 100644 --- a/C/Easy/9.c +++ b/C/Easy/9.c @@ -6,6 +6,6 @@ int main() { for (int i = 0; i <= 5; i++) { sum += arr[i]; } - printf("Sum of array elements: %d\n", sum); - return 0; -} + printf("Sum of array elements is: %d\n", sum); +    return 0; +} \ No newline at end of file From 8804ff130471e4e6430a4c0018ed56dafb5478ac Mon Sep 17 00:00:00 2001 From: ayushyadav092005 Date: Sat, 5 Oct 2024 13:38:07 +0530 Subject: [PATCH 60/62] Update 59.java --- Java/Easy/59.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Easy/59.java b/Java/Easy/59.java index af05903b..fe0d3f67 100644 --- a/Java/Easy/59.java +++ b/Java/Easy/59.java @@ -1,6 +1,6 @@ class Main { public static void main(String[] args) { String[] fruits = {"Apple", "Banana", "Mango"}; - System.out.println(fruits[-1]); + System.out.println(fruits[1]); } } From 20e19caf7c11af69b1d656b5d500e182002e7756 Mon Sep 17 00:00:00 2001 From: GDG-RAIT Date: Sat, 5 Oct 2024 13:48:49 +0530 Subject: [PATCH 61/62] Revert " 9 c" --- C/Easy/9.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/C/Easy/9.c b/C/Easy/9.c index 02d4e3d4..ca3c624c 100644 --- a/C/Easy/9.c +++ b/C/Easy/9.c @@ -6,6 +6,6 @@ int main() { for (int i = 0; i <= 5; i++) { sum += arr[i]; } - printf("Sum of array elements is: %d\n", sum); -    return 0; -} \ No newline at end of file + printf("Sum of array elements: %d\n", sum); + return 0; +} From 1026ad039ab3963e0eb045924e4dbbcd818411c4 Mon Sep 17 00:00:00 2001 From: AnshuXLynx Date: Sat, 5 Oct 2024 16:14:07 -0700 Subject: [PATCH 62/62] 52C.c --- C/Easy/52.c | 1 + 1 file changed, 1 insertion(+) diff --git a/C/Easy/52.c b/C/Easy/52.c index 8eae7301..043ecefe 100644 --- a/C/Easy/52.c +++ b/C/Easy/52.c @@ -2,6 +2,7 @@ #include int main() { int a; + scanf("%d",&a); printf("%d\n", a); return 0; }