TUGAS-2-MK-DAA-RASYA-ALFAHRIZI/TUGAS_4_4_RASYA_ALFAHRIZI_202510715125.ipynb

95 lines
2.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"**TUGAS 4.4 KATA YANG KAYA**"
],
"metadata": {
"id": "8VO4ws0B-P3Y"
}
},
{
"cell_type": "markdown",
"source": [
"Nama : Rasya Alfahrizi\n",
"NPM : 202510715125\n",
"Kelas : F2A1\n",
"\n",
"## Penjelasan\n",
"Program ini dibuat untuk menyelesaikan permasalahan dalam menentukan jumlah huruf unik terbanyak pada setiap baris kalimat. Setiap baris input terdiri dari beberapa kata yang hanya mengandung huruf kecil (az). Untuk setiap kata, program akan menghitung jumlah huruf yang berbeda (unik), kemudian menentukan nilai maksimum dari kata-kata dalam satu baris.\n",
"\n",
"Hasil akhir akan ditampilkan dalam format:\n",
"h#i: x\n",
"\n",
"Dimana:\n",
"\n",
"* i adalah nomor baris input\n",
"* x adalah jumlah huruf unik terbanyak pada baris tersebut\n",
"\n",
"## Tujuan\n",
"Tujuan dari program ini adalah untuk memahami penggunaan struktur data seperti set dalam menghitung elemen unik, serta melatih pengolahan string dalam pemrograman Python.\n",
"\n",
"## Bahasa yang Digunakan\n",
"Python\n"
],
"metadata": {
"id": "GLwY7utD-R7e"
}
},
{
"cell_type": "code",
"source": [
"n = int(input(\"Masukkan jumlah baris: \"))\n",
"\n",
"for i in range(1, n + 1):\n",
" line = input()\n",
" words = line.split()\n",
"\n",
" max_unique = 0\n",
" for word in words:\n",
" unique_letters = len(set(word))\n",
" max_unique = max(max_unique, unique_letters)\n",
"\n",
" print(f\"h#{i}: {max_unique}\")\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "0TMaExna-Sge",
"outputId": "6426f0b2-3a59-4a85-d5e9-7bdc5cca665a"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Masukkan jumlah baris: 3\n",
"kata di ujung pena\n",
"h#1: 4\n",
"juli di bulan juni\n",
"h#2: 5\n",
"daun di atas bantal\n",
"h#3: 5\n"
]
}
]
}
]
}