If/Else


To implement this situation with the help of Python we can use the next code:
9
1
2
3
4
5
6
# 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!')
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.
- Set the condition if the
price
is greater than25
. - Set the
25%
discount if theprice
is greater than25
.!
- Otherwise, set the
10%
discount. - Print the
price_upd
.
!
To set the 25%
discount use value * 0.75
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
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?
Thanks for your feedback!
Section 2. Chapter 1
single
99
1
2
3
4
5
6
7
8
9
10
11
12
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
___(___)
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat