COURSES
MBAData Science & AnalyticsDoctorate Software & Tech AI | ML MarketingManagement
Professional Certificate Programme in HR Management and AnalyticsPost Graduate Certificate in Product ManagementExecutive Post Graduate Program in Healthcare ManagementExecutive PG Programme in Human Resource ManagementMBA in International Finance (integrated with ACCA, UK)Global Master Certificate in Integrated Supply Chain ManagementAdvanced General Management ProgramManagement EssentialsLeadership and Management in New Age BusinessProduct Management Online Certificate ProgramStrategic Human Resources Leadership Cornell Certificate ProgramHuman Resources Management Certificate Program for Indian ExecutivesGlobal Professional Certificate in Effective Leadership and ManagementCSM® Certification TrainingCSPO® Certification TrainingLeading SAFe® 5.1 Training (SAFe® Agilist Certification)SAFe® 5.1 POPM CertificationSAFe® 5.1 Scrum Master Certification (SSM)Implementing SAFe® 5.1 with SPC CertificationSAFe® 5 Release Train Engineer (RTE) CertificationPMP® Certification TrainingPRINCE2® Foundation and Practitioner Certification
Law
Job Linked
Bootcamps
Study Abroad
MS in Data AnalyticsMS in Project ManagementMS in Information TechnologyMasters Degree in Data Analytics and VisualizationMasters Degree in Artificial IntelligenceMBS in Entrepreneurship and MarketingMSc in Data AnalyticsMS in Data AnalyticsMS in Computer ScienceMaster of Science in Business AnalyticsMaster of Business Administration MS in Data ScienceMS in Information TechnologyMaster of Business AdministrationMS in Applied Data ScienceMaster of Business Administration | STEMMS in Data AnalyticsM.Sc. Data Science (60 ECTS)Master of Business AdministrationMS in Information Technology and Administrative Management MS in Computer Science Master of Business Administration MBA General Management-90 ECTSMSc International Business ManagementMS Data Science Master of Business Administration MSc Business Intelligence and Data ScienceMS Data Analytics MS in Management Information SystemsMSc International Business and ManagementMS Engineering ManagementMS in Machine Learning EngineeringMS in Engineering ManagementMSc Data EngineeringMSc Artificial Intelligence EngineeringMPS in InformaticsMPS in Applied Machine IntelligenceMS in Project ManagementMPS in AnalyticsMS in Project ManagementMS in Organizational LeadershipMPS in Analytics - NEU CanadaMBA with specializationMPS in Informatics - NEU Canada Master in Business AdministrationMS in Digital Marketing and MediaMSc Sustainable Tourism and Event ManagementMSc in Circular Economy and Sustainable InnovationMSc in Impact Finance and Fintech ManagementMS Computer ScienceMS in Applied StatisticsMaster in Computer Information SystemsMBA in Technology, Innovation and EntrepreneurshipMSc Data Science with Work PlacementMSc Global Business Management with Work Placement MBA with Work PlacementMS in Robotics and Autonomous SystemsMS in Civil EngineeringMS in Internet of ThingsMSc International Logistics and Supply Chain ManagementMBA- Business InformaticsMSc International ManagementMBA in Strategic Data Driven ManagementMSc Digital MarketingMBA Business and MarketingMaster of Business AdministrationMSc in Sustainable Global Supply Chain ManagementMSc Digital Business Analytics MSc in International HospitalityMSc Luxury and Innovation ManagementMaster of Business Administration-International Business ManagementMS in Computer EngineeringMS in Industrial and Systems EngineeringMSc International Business ManagementMaster in ManagementMSc MarketingMSc Business ManagementMSc Global Supply Chain ManagementMS in Information Systems and Technology with Business Intelligence and Analytics ConcentrationMSc Corporate FinanceMSc Data Analytics for BusinessMaster of Business AdministrationMaster of Business AdministrationMaster of Business AdministrationMSc in International FinanceMSc in International Management and Global LeadershipMaster of Business AdministrationBachelor of BusinessMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSMaster of Business Administration 90 ECTSBachelor of Business AnalyticsBachelor of Information TechnologyMaster of Business AdministrationMBA Business AnalyticsMSc in Marketing Analytics and Data IntelligenceMS Biotechnology Management and EntrepreneurshipMSc in Luxury and Fashion ManagementMaster of Business Administration (90 ECTS)Bachelor of Business Administration (180 ECTS)B.Sc. Computer Science (180 ECTS) MSc in International Corporate Finance MSc in Sustainable Luxury and Creative IndustriesMSc Digital Marketing
For College Students

Decision Making in Python

$$/$$

In the last session, you understood about dictionaries; now, try to answer this simple question on dictionaries.

 

Dict = {1:'Asia',2:'Africa'}

 

From this dictionary, return the value when the key is 3, and if the key is missing, return ‘NA’. You cannot use Dict[3] because it throws an error, as 3 is not present in the dictionary. Instead, you can use the dictionary get method: Dict.get(3,'NA').

 

So, what exactly is happening using this method that is helping us avoid an error?

This method simply establishes a condition that specifies: if a key is absent, then print NA. This is nothing but an if-else construct. Before we look at the if-else construct, let’s quickly understand binary and relational operators. 

$$/$$

Having understood about relational operators, let’s now look at the if-else construct and the role of these relational operations in its implementation.

if-elif
$$/$$

In the example discussed above: 

x = 10

if x%2  == 0:
    print(x, "is even number")
else:
  print(x, "is odd number")

 

x % 2 == 0 is a relational condition that would return 'true' or 'false' based on the value of x. If this condition is true, the set of statements under the if-block will be executed; otherwise, the statements under the else-block will be executed. 

 

Important things to note here are as follows:

 

The colon that indicates the start of block creation, The indentation here defines the scope of the if- or else- statement, Either code under the if-block is executed or under the else-block is executed, not both of them. 

 

So now that you have understood the basic if-else construct, can you try to write a code to return YES if x lies in the range of 1000 to 1100, else return NO?

 

If you break this down, you can get the following conditions:

 

Implementation:

if (X<1000):
    print('No')
else:
    if (X>1100 ):
        print('No')
    else:
        print('Yes')

 

You may think that this is not possible using a single if-else statement, but that is not true. You can use the logical operators in Python and combine two conditions. Let’s look at them in the following video:

    $$/$$

    In the video, you learnt that there are three types of logical operators: 

     

    If you apply this concept to our earlier example for checking whether x lies in the range of 1000 to 1100, the code gets modified as shown below:

    if (X>1000 & X<1100):
        print('YES')
    else:
        print('No')
    

     

    Isn’t this simple compared with the earlier code? That is how logical operators make our logic building easy.

     

    Similar to an if-else construct, there is if-elif-else construct available in Python. Let’s understand it by looking at an example in our next video.

    $$/$$

    In the example shown in the video:

    if shoppinng_total >= 5000:
        print("You won a discount voucher of flat 1000 on next purchase")
    else:    
        if shoppinng_total >= 2500 :
            print("You won a discount voucher of flat 500 on next purchase")
        else:
            if shoppinng_total >= 1000:
                print("You won a discount voucher of flat 100 on next purchase")    
            else:
                print("OOPS!! no discount for you!!!")
    

     

    Using an if-else construct would also give us an answer, but imagine that you have 10 conditions like this; wouldn’t it be clumsy? Instead, if you use something like an elif-construct, it would make the code more readable. 

     

    In this segment, you learnt about relational operators, logical operators, if-else, if-elif- else and nested if-else constructs. You might be pretty confused about when to use each of them. Read the tips given below, which may help you to arrive at a conclusion faster.

     

    TIPS:

    When there is more than one condition to check and you need to:

    1. Perform a different operation at each condition involving a single variable, you use an if-elif-else condition.
    2. Just return a boolean functionality, i.e., Yes or No, you use logical operators in a single if-else construct.
    3. Perform a different operation in each condition involving different variables, you use a nested if-else construct.
    $$/$$

    In the next segment, you will learn about the uses of looping constructs such as ‘for’ loops and ‘while’ loops.