Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn If/Else | Introduction to Python 2/2
Introduction to Python for Data Analysis

book
If/Else

carousel-imgcarousel-img

To implement this situation with the help of Python we can use the next code:

# What year did the first computer appear?
i = 1927
if i == 1927:
print('You are right!')
else:
print('You are not right!')
123456
# What year did the first computer appear? i = 1927 if i == 1927: print('You are right!') else: print('You are not right!')
copy

Now we will implement if/else to find updated prices (with different discounts) for the subscriptions.

Task

Swipe to start coding

Analysts decided to update subscription prices.

They want to set a 25% discount if the price is higher than 25. In other cases, they want to set a 10% discount.

  1. Set the condition if the price is greater than 25.
  2. Set the 25% discount if the price is greater than 25. !
  3. Otherwise, set the 10% discount.
  4. Print the price_upd.

! To set the 25% discount use value * 0.75

Solution

price = 25

# Set the condition if the subscription price id greater than 25
if price > 25:
# Set the 25% discount
price_upd = price * 0.75
else:
# Set the 10% discount
price_upd = price * 0.9

# Print the new price
print(price_upd)

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1
price = 25

# Set the condition if the subscription price is greater than 25
if ___ > ___:
# Set the 25% discount
price_upd = ___ * ___
else:
# Set the 10% discount
price_upd = ___ * ___

# Print the new price
___(___)
toggle bottom row
some-alt