From 3057f9fb03784d4adc22cf37df42c333d5c823e2 Mon Sep 17 00:00:00 2001 From: Asabeneh Date: Wed, 7 Jul 2021 05:14:45 +0300 Subject: [PATCH] second version conditionals --- 09_Day_Conditionals/09_conditionals.md | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/09_Day_Conditionals/09_conditionals.md b/09_Day_Conditionals/09_conditionals.md index 6408b5d..506ef1d 100644 --- a/09_Day_Conditionals/09_conditionals.md +++ b/09_Day_Conditionals/09_conditionals.md @@ -9,10 +9,9 @@ Author: Asabeneh Yetayeh
- First Edition: Nov 22 - Dec 22, 2019 + Second Edition: July, 2021
- [<< Day 8](../08_Day_Dictionaries/08_dictionaries.md) | [Day 10 >>](../10_Day_Loops/10_loops.md) @@ -29,19 +28,20 @@ - [If Condition and Logical Operators](#if-condition-and-logical-operators) - [If and Or Logical Operators](#if-and-or-logical-operators) - [πŸ’» Exercises: Day 9](#-exercises-day-9) + - [Exercises: Level 1](#exercises-level-1) # πŸ“˜ Day 9 ## Conditionals -By default, statements in python script are executed sequentially from top to bottom. If the processing logic require so, the sequential flow of execution can be altered in two way: +By default, statements in Python script are executed sequentially from top to bottom. If the processing logic require so, the sequential flow of execution can be altered in two way: - Conditional execution: a block of one or more statements will be executed if a certain expression is true - Repetitive execution: a block of one or more statements will be repetitively executed as long as a certain expression is true. In this section, we will cover _if_, _else_, _elif_ statements. The comparison and logical operators we learned in previous sections will be useful here. ### If Condition -In python and other programming languages the key word _if_ we use to check if a condition is true and to execute the block code. Remember the indentation after the colon. +In python and other programming languages the key word _if_ is used to check if a condition is true and to execute the block code. Remember the indentation after the colon. ```py # syntax @@ -196,10 +196,12 @@ else: print('Access denied!') ``` -πŸŒ• You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. +πŸŒ• You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and muscles. ## πŸ’» Exercises: Day 9 +### Exercises: Level 1 + 1. Get user input using input(β€œEnter your age: ”). If user is 18 or older, give feedback: You are old enough to drive. If below 18 give feedback to wait for the missing amount of years. Output: ```sh Enter your age: 30 @@ -219,7 +221,9 @@ else: Enter number two: 3 4 is greater than 3 ``` -4. Write a code which gives grade to students according to theirs scores: + + ### Exercises: Level 2 + 4. Write a code which gives grade to students according to theirs scores: ```sh 80-100, A 70-89, B @@ -237,7 +241,8 @@ else: fruits = ['banana', 'orange', 'mango', 'lemon'] ``` If a fruit doesn't exist in the list add the fruit to the list and print the modified list. If the fruit exists print('That fruit already exist in the list') -7. Here we have a person dictionary. Feel free to modify it! + ### Exercises: Level 3 + 7. Here we have a person dictionary. Feel free to modify it! ```py person={ 'first_name': 'Asabeneh', @@ -252,10 +257,11 @@ else: } } ``` - * Check if the person dictionary has skills key, if so print out the middle skill in the skills list. - * Check if the person dictionary has skills key, if so check if the person has 'Python' skill and print out the result. - * If a person skills has only JavaScript and React, print('He is a front end developer'), if the person skills has Node, Python, MongoDB, print('He is a backend developer'), if the person skills has React, Node and MongoDB, Print('He is a fullstack developer'), else print('unknown title') - for more accurate results more conditions can be nested! - * If the person is married and if he lives in Finland, print the information in the following format: + + * Check if the person dictionary has skills key, if so print out the middle skill in the skills list. + * Check if the person dictionary has skills key, if so check if the person has 'Python' skill and print out the result. + * If a person skills has only JavaScript and React, print('He is a front end developer'), if the person skills has Node, Python, MongoDB, print('He is a backend developer'), if the person skills has React, Node and MongoDB, Print('He is a fullstack developer'), else print('unknown title') - for more accurate results more conditions can be nested! + * If the person is married and if he lives in Finland, print the information in the following format: ```py Asabeneh Yetayeh lives in Finland. He is married. ```