Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Incrementing and Decrementing | Control Flow
Introduction to Data Analysis in Python
course content

Kursinnehåll

Introduction to Data Analysis in Python

Introduction to Data Analysis in Python

1. Basics
2. Data Types
3. Control Flow
4. Functions and Modules
5. Introduction to NumPy

book
Incrementing and Decrementing

Look at the table to understand how to minimize the writing of mathematical operators!

FormulaHow to minimize
a = a + 1a += 1
a = a - 1a -= 1
a = a * 2a *= 2
a = a / 2a /= 2

Consider list of prices named prices. If price is greater than 30, then the 25% discount must be set. If not, then price must be reduced by 3. Check out how can we do it with the for loop.

123456789101112131415161718
prices = [20.35, 30.5, 12.65, 8.5, 6.5, 5.8, 40.5] print(prices) prices_upd = [] # Set the for loop for price in prices: # Condition: the element of the list is greater than 30 if price > 30: # Set the 25% discount price *= 0.75 else: # Decrease the price by 3 price -= 3 # Appending values to the upd list prices_upd.append(price) # Print the prices_upd print(prices_upd)
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 8

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

Introduction to Data Analysis in Python

Introduction to Data Analysis in Python

1. Basics
2. Data Types
3. Control Flow
4. Functions and Modules
5. Introduction to NumPy

book
Incrementing and Decrementing

Look at the table to understand how to minimize the writing of mathematical operators!

FormulaHow to minimize
a = a + 1a += 1
a = a - 1a -= 1
a = a * 2a *= 2
a = a / 2a /= 2

Consider list of prices named prices. If price is greater than 30, then the 25% discount must be set. If not, then price must be reduced by 3. Check out how can we do it with the for loop.

123456789101112131415161718
prices = [20.35, 30.5, 12.65, 8.5, 6.5, 5.8, 40.5] print(prices) prices_upd = [] # Set the for loop for price in prices: # Condition: the element of the list is greater than 30 if price > 30: # Set the 25% discount price *= 0.75 else: # Decrease the price by 3 price -= 3 # Appending values to the upd list prices_upd.append(price) # Print the prices_upd print(prices_upd)
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 8
Vi beklagar att något gick fel. Vad hände?
some-alt