# Kategori: Program Python

• ## Program kanggo Menara Hanoi nggunakake Python

Introduction The task is to solve Tower of Hanoi problem using python programming. There are set of rules to follow while solving the problem: At a time only one disk is allowed to be moved. Only the uppermost disk is allowed to be moved. Disks can only be placed on the top of larger disks.…

• ## Program kanggo nyithak nomer digit paling cilik sing bisa dibagi dening n nggunakake Python

Introduction The task to find and print the smallest M digit number divisible by N. Program def result(n, m):     x = pow(10, m-1)        if( x % n == 0):         print(x)          else:         print((x + n) – ((x + n) % n))    n = 64  m = 8  result(n, m)…

• ## Program kanggo nemokake produk saka faktor prima unik saka nomer diwenehi nggunakake Python

Introduction The task is to print the product of unique prime factors of the given number. Program def find(ip_num): # Initializing product with 1     prod = 1     for num in range(2, ip_num+1):         if (ip_num % num == 0):             prime_true = 1                          for num2 in range(2, int(num/2 + 1)):                 if…

• ## Program kanggo Sieve of Eratosthenes nggunakake Python

Introduction The task is to print all the prime numbers smaller than or equal to the given number n (given n must be small).   Program def SOE(ip_num): # Initialize all the element with True, the value will be False if p_num[val] is not prime     p_num = [True for val in range(ip_num + 1)]…

• ## Program kanggo nyithak matriks ing wangun Z nggunakake Python

Introduction Given a matrix of size n*n, the task is to print the elements in Z form. Program ip_array = [[1, 2, 3],                     [4, 5, 6],                     [7, 8, 9]] length = len(ip_array[0]) #Print first line                   n = 0 for m in range(0, length):     print(ip_array[n][m])  #Print diagonals          l = 1 for…

• ## Program kanggo nomer masalah stasiun mandeg nggunakake Python

Introduction The task is to find the number of ways we can stop the train at K stations out of N stations between S1 and S2 such that the stopping stations are non-consecutive. Program def find( s, ts): #select s non-consecutive station from ts number of stations “        temp, temp1  = 1, 1    …

• ## Program kanggo nemokake karakter sing paling kerep karo count kedadean nggunakake Python

Introduction The task is to find the frequent occurred character in the given string with it occurrence number.   Program from collections import Counter def find(ip_char):     count = Counter(ip_char) # Most occured char     max_occur = max(count.values())     index = count.values().index(max_occur)        print(count.items()[index]) ip_char = ‘alphabet’ find(ip_char) Output (‘a’, 2) Explanation In the…

• ## Program kanggo nemokake jumlah minimal faktor nomer diwenehi nggunakake Python

Introduction The task is to find the minimum sum of factors of the given number. Program def find(ip_no): # Initilize sum with 0     output_sum = 0     fact = 2     while(fact * fact <= ip_no):         while(ip_no % fact == 0):             output_sum += fact             ip_no /= fact         fact += 1…

• ## Program kanggo nemokake dhuwur maksimum nalika dhuwit recehan sing disusun ing triangle nggunakake Python

Introduction Given N number of coins, the task is to construct a triangle of maximum height H and print the max height. Program def sq_root(val):     n = val      m = 1 # Accuracy       e = 0.000001     while (n – m > e):         n = (n + m) / 2        …

• ## Program kanggo konjektur Legendre nggunakake Python

Introduction There is always one prime between n2 and (n+1)2 . The task is to print all the prime number between the range n2 to (n+1)2 .     Program import math  def check( ip_num ):     n = 2     for n in range (2, int((math.sqrt(ip_num)+1))):         if ip_num % n == 0:            …