Advertisement
Dar954826

Fattori Primi[ITA].py

Oct 25th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import math
  2. import os
  3. def fattori() :
  4.  global dir1
  5.  global a
  6.  global a1
  7.  global factor,sf1,sf,maxnum
  8.  factor=""
  9.  dir1=[]
  10.  a1=input("Inserisci il numero da scomporre: ")
  11.  try:
  12.   a=int(a1)
  13.   while a>1:
  14.    global b
  15.    b=2
  16.    for x in range(999999999999999):
  17.     if a%b!=0:
  18.      b=b+1
  19.     elif a%b==0:
  20.      c=a/b
  21.      a=int(a)
  22.      c=int(c)
  23.      dir1.append(b)
  24.      maxnum=b
  25.      print(a, "|", b, "=", c)
  26.      a=a/b
  27.      break
  28.   for sf in range(maxnum+5):
  29.    if dir1.count(sf)!=0:
  30.     sf2=dir1.count(sf)
  31.     sf1=str(sf)
  32.     sf21=str(sf2)
  33.     factor=factor+sf1+"^"+sf21+"*"
  34.   print("\n"*2)
  35.   print("Fattorizzazione:")
  36.   frg=len(factor)
  37.   print(factor[0:frg-1])
  38.   print("\n"*2)
  39.   input("Clicca per continuare")
  40.   print("\n"*1000)
  41.  except ValueError:
  42.   input("Puoi inserire solo numeri")
  43.   print("\n" *1000)
  44.   os.system("exit")
  45.  
  46. oop=bool("false")
  47. while oop:
  48.  fattori()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement