Prova le funzioni (int)

Le funzioni che restituiscono un numero int (intero) si trovano tra quelle predefinite e nei moduli fractions, math, random, statistics, …

  • abs(), int(), len(), max(), min(), ord(), round(), pow(), sum()
  • math.ceil(), math.floor(), math.factorial(), math.gcd(), math.trunc()
  • random.randint()
  • statistics.mode()

Prova

  • Copia il codice delle funzioni che ti interessano
  • Assegna un valore alla/e variabile/i
  • Alcune funzioni restituiscono un valore intero se anche l’argomento(i) è intero: abs(), pow()
print("       abs(", x, ") ="            ,        abs(x)       )  # Se x è intero...
print("  math.ceil(", x, ") ="           ,   math.ceil(x)      )  # x float, x Fraction
print("  math.floor(", x, ") ="          ,   math.floor(x)     )  # x float, x Fraction
print("  math.factorial(", n, ") ="      ,   math.factorial(n) )
print("  math.gcd(", a, ",", b, ") ="    ,   math.gcd(a, b)    )  # a,b interi
print("       int() ="                   ,        int()        )  # 0
print("       int(", s, ") ="            ,        int(s)       )  # s stringa
print("       int(", x, ") ="            ,        int(x)       )  # x float
print("       len(", z, ") ="            ,        len(z)       )  # z sequenza
print("       max(", x1, ",", x2, ") ="  ,        max(x1, x2)  )  # Se il max è intero... 
print("       min(", x1, ",", x2, ") ="  ,        min(x1, x2)  )  # Se il min è intero... 
print("       ord(", c, ") ="            ,        ord(c)       )  # Se c è un carattere...
print("       round(", x, ") ="          ,        round(x)     )  # x float, x Fraction
print("       pow(", x1, ",", x2, ") ="  ,        pow(x1, x2)  )  # Se x1, x2 sono interi...
print("random.randint(", a, ",", b, ") =", random.randint(a, b))
print("  math.trunc(", x, ") ="          ,   math.trunc(x)     )  # x float, x Fraction

Se z è una sequenza di valori numerici

print("statistics.mode(z) =", statistics.mode(z))   # Se il primo valore della moda è intero... 
print("           sum(z) =" ,            sum(z) )   # Se gli elementi di z sono tutti interi...