Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Padroneggiare i Numeri Interi in Python | Familiarizzarsi con i Numeri in Python
Tipi di Dati in Python

book
Padroneggiare i Numeri Interi in Python

Potresti essere abituato a specificare i numeri in modi come:

  • 1,000,000 (con virgole);

  • 1 000 000 (con spazi).

Tuttavia, Python non capirà questo. 😢

Questi formati sono comprensibili per una persona ma non per un computer, quindi il modo corretto è 1000000 senza virgole o spazi.

python
var = 1000000

Se vuoi usare separatori per una migliore leggibilità, Python consente la seguente sintassi:

python
var = 1_000_000
Compito

Swipe to start coding

Una piccola azienda sta pianificando il suo budget per i primi due trimestri dell'anno. Tuttavia, alcune cifre finanziarie devono essere formattate correttamente.

Ecco i budget allocati:

  • Allocazione del budget Q1: q1_budget = 750000.
  • Allocazione del budget Q2: q2_budget = 1200500.

Adatta questi valori in modo che siano compatibili e stampali.

Soluzione

# Define integer variables
q1_budget = 750000
q2_budget = 1_200_500

# Print the variables
print("The initial Q1 budget was 750,000 and the corrected is:", q1_budget)
print("The initial Q2 budget was 1 200 500 and the corrected is:", q2_budget)
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 3
# Define integer variables
q1_budget = 750,000
q2_budget = 1 200 500

# Print the variables
print("The initial Q1 budget was 750,000 and the corrected is:", ___)
print("The initial Q2 budget was 1 200 500 and the corrected is:", ___)

Chieda ad AI

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt