Python for non-Pythonians by Grossetti Francesco; Rubera Gaia;

Python for non-Pythonians by Grossetti Francesco; Rubera Gaia;

Author:Grossetti, Francesco; Rubera, Gaia;
Language: eng
Format: epub
Publisher: EGEA Spa - Bocconi University Press
Published: 2019-06-14T00:00:00+00:00


“If we sell more than 10 coffee, just let me know it otherwise apply a 10% discount.”

The word otherwise is translated in Python by the reserved keyword else. and the use is similar to if. Of course, there wouldn’t be any otherwise without an if so the else command works in conjunction with if. Let’s write in Python the above statement:

n_coffee = 5 if n_coffee >= 10: print('You just sold more than 10 coffees') else: print('Buy a coffee with 10% discount!') ## Buy a coffee with 10% discount!

As you can see, Python checked the first condition given by the if and found it to be false. Then it checked the way out given by the else and found it to be true so it printed the message.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.