Advertisement
ruhan008

Python Assignment 3

Feb 2nd, 2024 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. k_values = [5,6,7,8,9,10]
  2.  
  3. number = """80305819756942201375489585898582728359125376393672671890721258654640153063276854646941512424482871973450275648094326370821684146232021234968910743756427552137119181427345918091192930953879191131615498683155730974186245381895299995291613811708839994166310513251189919219826383686381464772845357534156859312826087485080157185139202555905605217833563998277996607549524048542945963928412993312995837811367747710931675453035653603870077749346653539898270498391583882067683196221572122566860049520394681148043214626713474719896643906244563446783220621099157896055732912725327667265881006760363373158076659578274777675940242792984297001876714737941868642345530486796146981710372091896896539704018815333888513675015212932696404070975645710269418633"""
  4.  
  5. answer = [0,0,0,0,0,0]
  6. for i in range(0,len(k_values)):
  7.     k = k_values[i]
  8.     maximum_product = 0
  9.  
  10.     for j in range(0,len(number)-k+1):
  11.         product = 1;
  12.         for l in range(j,j+k):
  13.             num = int(number[l])
  14.             product = product * num
  15.  
  16.         if(product > maximum_product):
  17.             maximum_product = product
  18.  
  19.     answer[i] = maximum_product
  20.  
  21. for i in range(0,len(answer)):
  22.     print("K =",k_values[i],", Answer =",answer[i])
  23.  
  24.  
  25. # OUTPUT:
  26.    
  27.     # K = 5 , Answer = 32805
  28.     # K = 6 , Answer = 186624
  29.     # K = 7 , Answer = 1036800
  30.     # K = 8 , Answer = 8294400
  31.     # K = 9 , Answer = 41472000
  32.     # K = 10 , Answer = 331776000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement