Author name: cndro

Blogs

Tableau Server Client (TSC)

There are different methods used in communicating with the Tableau Server, but one of the outstanding methods is through the Tableau Server Client (TSC). The tableau server is one of the tools in the tableau software product suite. You can read about tableau and it’s tools here. In this article, I am going to share with you what TSC is and how important it is to any Tableau developer What is TSC? Tableau Server Client (TSC) is a python library for the Tableau Server REST API. You can do almost everything on the Tableau Server with the REST API. You can create users, create groups, query projects, query sites to retrieve data sources and workbooks, you can do so much more on the Tableau Server just with the Tableau Server Client. One of the strengths of this python library (TSC), is that you can query multiple data sources and workbooks at a time. TSC allows you to communicate with the tableau server using python programming language, giving you more control over the server. Downloading datasources from Tableau server using TSC. Downloading data sources is an inevitable task for every tableau developer. Since this task is a very common one, I am going to show you how to carry it out effectively using TSC. I’m going to do a quick walkthrough of how to download all the datasources that has been published to the Tableau server default site. For this purpose of this article, I’m going to use the Jupyter notebook. You can also use your favorite IDE to carry out this process. This process is the same for all versions of the tableau server, but I used version 10.5.3. So, let’s jump right in: Step 1: Launch Jupyter notebook. Install TSC using the python line below: !pip install tableauserverclient Step 2: Once the library has been installed, authenticate the connection to the TSC so that Tableau server can identify you as a user. tableau_auth = TSC.TableauAuth(‘USERNAME’, ‘PASSWORD’, ‘SITENAME’) In your case, input your username and password in the respective fields, and “default” as the sitename, because we are trying to download datasources from the default site. If it was from a different site, you will input the name of the site instead. Step 3: After the authentication stage, declare your server to establish a connection between TSC and the server. This can be done with this line of code: server = TSC.Server(‘Your Tableau Server Public IP’) Step 4: Get all the datasources in the default site using this line of code: with server.auth.sign_in(tableau_auth):     all_datasources, pagination_item = server.datasources.get() Step 5: Get all the IDs of the datasources so you can use it in referencing the operations that you want to perform on the site. The code for this step is:     datasource_ids = [datasource.id for datasource in all_datasources]  Step 6: Print the total number of datasources in the default site. Then, print the number of the datasources to be downloaded from the server 10.5.3   print(“\nThere are {} datasources on site “.format(len(all_datasources)))    print(“\nThere are {} datasources to be downloaded on site:  “.format(pagination_item.total_available)) Step 7: Loop through the datasources using their ids and download the datasources to your local machine.     for id in datasource_ids:          if file_download.lower().endswith(‘.tdsx’):          file_download = server.datasources.download(id)         print(file_download)   Step 9: Finally, sign out of the server so your information on it is saved. server.auth.sign_out()  Your Jupyter notebook should look like this image below:   How to download datasources from the tableau server default site. Importance of Tableau Server Client to a Tableau Developer As a Tableau developer, having full understanding and control of the Tableau server is of extreme importance. Tableau Server administration is a required skill in the 21st century as a Tableau Developer. TSC helps you to administer your tableau server easily. It makes you able to send instructions to your server from your local computer, publish datasources and workbooks to the server from your local machine.

Blogs

How to import multiple files in Python

Most times in Python, you get to import just one file using pandas by pd.read(filename) or using the default open() and read() function in. But news flash, you can actually do more!! In this article, I am going to show you how to import multiple files into your Python IDE. Please note that the IDE I used for this process is Jupyter notebook. Pandas can be used to read certain file types as specified in jupyter notebook. These file types include: 1. clipboard 2. Csv 3. excel 4. Feather 5. Fwf 6. Gbq 7. Hdf 8. Html 9. Json 10. Msgpack 11. Parquet 12. Sas 13. Sql 14. Sql query 15. Sql table 16. Stata 17. Table To see this list in your jupyter notebook. This is all you have to do. 1. Be sure you have pandas installed Pip install pandas 2. Import pandas into your jupyter notebook Import pandas as pd 3. Try to read your file and check for other file formats that can be read in python Data = pd.read_#fileformat(filename) (#fileformat is just a place holder for the file format) After the underscore(_) press the tab key on your keyboard. Importing multiple files in Python Importing multiple files in python is done with a module called GLOB Glob is a module that helps to import any file format into python notebook. It is used with several wildcards to import specific file types to prevent import unnecessary files not needed in your python notebook. To get glob installed, you have to run a pip command in your command prompt or Anaconda Prompt Pip install glob3 Importing glob into python (Anaconda) Import glob Importing all the file in your current directory Myfiles = [I for in glob.glob(‘*’)] Note: * is a wildcard which denotes all. This takes all the files in that current directory into python. Importing all excel file formats in Python Myfiles = [I for in glob.glob(‘*.xlsx’)] The above code can also be written in the default way as shown below: Myfiles = [] (This is an empty list) Creating the for loop For each_file in glob.glob(‘*.xlsx’): Myfiles.append(each_file) Print(Myfiles) This will give you all the excel files in your current directory. On occasions where there are fields like data1.xlsx, data2.xlsx, data3.xlsx, data21.xlsx, data22.xlsx, e.t.c; we can use a wildcard (?) to pick certain files. Mynewfiles = [] For each_file in glob.glob(‘data?.xlsx’): Mynewfiles.append(each_file) Print(Mynewfiles) The code above will give us files with the name data1.xlsx, data2.xlsx, data3.xlsx without data21.xlsx, data22.xlsx even though it is an excel format (.xlsx) Import files with a range of numbers Mynewfiles2 = [] (This is an empty list) For each_file in glob.glob(‘data[0-9].xlsx’): Mynewfiles2.append(each_file) Print(Mynewfiles2) This will return files with the numerical values in the specified location in the specified range. Placeholders Using placeholders can be fun just to make your codes more readable and understandable. Combining {} and .format helps in achieving this. Importing only csv files csv_files = [] for each_file in glob.glob(‘*.{}’.format(‘csv’)): csv_files.append(each_file) print(csv_files) Most times, it is preferred to have your file format assigned to a variable. Importing an XML file Fileformat = ‘xml’ xml_files = [] for each_file in glob.glob(‘*.{}’.format(fileformat)): xml_files.append(each_file) print(xml_files) You can import any file format into python using the above method python. To read these files, you can use the open and read functions in python as seen below: for each_data in xml_files: print(open(each_data, ‘r’)) print(open(each_data, ‘r’).read()) This would return the contents of the file (the xml file).

Blogs

10 Important String Functions in Tableau

In Tableau, strings or string data, are data made of text. String functions exist to help you manipulate your string data. There about twenty string functions in Tableau. In this article, I am going to introduce you to ten (10) important string functions in Tableau, and how to use them. You might be wondering “why are string functions so important?” Let’s assume a scenario where you want to pull the first name of all your customers into a new field; a string function will handle that task for you. String Functions In Tableau Important String Functions in Tableau Please note that all the string functions in Tableau are of extreme importance. This article is just exploring 10 of them, and they include: ASCII CONTAINS FIND LEFT LEN MID REGEXP_MATCH REGEXP_REPLACE SPLIT TRIM 1. ASCII This returns the ASCII code value of the first character in a string ASCII ( String ) ASCII (“authors”) = 97 2. CONTAINS This returns a TRUE if the specified substring is present in the given string. CONTAINS ( String, Substring ) CONTAINS (“Calculation” , “alcu”) 3. FIND This returns the position of the specified substring within the given string and returns 0 if the substring is not found. FIND (String, Substring, [ Start ]) The first character in the string is position 1 (not a 0 index). FIND (“Calculation”, “alcu”) = 2 If the start argument is defined, any instance of the substring that appears before the start position are ignored FIND (“Calculation”, “a”, 3 ) = 7 4. LEFT LEFT ( String, num_chars) This returns the specified number of characters from the start of the given string. LEFT (“Calculation”, 5 ) = “Calcu” 5. LEN LEN (String) This returns the number of characters in the given string. LEN (“Calculation”) = 11 6. MID MID (String, Start, [length]) This returns the characters from the middle of a text string given a starting position and a length. The first character in the string is in position 1. If the length is not included, all characters to the end of the strings are not returned. MID (“Tableau Software”,  9 ) = “Software” If the length is included, up to that many characters are returned. MID (“Tableau Software”, 2, 4) = “able” 7. REGEXP_MATCH REGEXP_MATCH ( String , Pattern ) This returns true if a substring of the provided string matches the regular expression pattern. REGEXP_MATCH ( ‘ – ( [1234] . [ The.Market] ) -’ ,  ‘\ [\s*(w*\.)  (  \w*\s*\]) ‘ ) = true 8. REGEXP_REPLACE REGEXP_REPLACE ( String, Pattern, replacement) This returns a copy of a given string where the matching pattern is substituted with the replacement string. REGEXP_REPLACE ( ‘abc123’, ‘\s’, ‘-’ ) = ‘abc–123’ 9. SPLIT SPLIT ( String , delimiter, token number) This returns a substring from a string as determined by a delimiter (a separator) extracting the characters from the beginning or end of the string. SPLIT (‘a/b/c/d’ , ‘ / ‘ , 2 ) = ‘b’ A negative token number can also be used. SPLIT (‘a/b/c/d’ , ‘ / ‘ ,  -2 ) =  ‘c’ 10. TRIM TRIM (String) This returns the string with both leading (LTRIM is used for this only ) and trailing (RTRIM is used for this only ) whitespaces removed. TRIM (“  Budget   ”)  =  “Budget” To learn more about all the string functions in tableau, click here.

Blogs

Salesforce: A software for every organization

Salesforce is a CRM which stands for Customer Relationship Management.  In very simple terms, it is an online tool that helps businesses manage their customer information (basically a database of customers) efficiently. Salesforce is a software for every organization, and in this article, I’m going to tell you why. Salesforce organizes data into objects and records just like in an excel spreadsheet where objects are like tabs and a record is like a single row of data. It can also be a unified place to do stuff with the company’s information stored on the secured cloud which makes data accessible anywhere and anytime in the world. Salesforce: A must-have Here are some of the reasons why the software is a must-have for every organization: Flexibility in capacity One of the most significant unique selling points of the Salesforce platform is its high degree of adaptability. The objects to be found in Salesforce can be set entirely in line with your desires at any time. As a user, you are not tied into certain set page layouts, workflows, and processes, and this makes Salesforce’s ecosystem more flexible than other similar systems on the market. Security Salesforce has some security basics that keep your data secured by authenticating users, giving only users access to the data in the company, also sharing objects and fields while monitoring the organization’s security. Countless options with various apps In addition to the clouds we have designed ourselves, Salesforce’s ecosystem also comprises applications you can purchase through the App Exchange. A major benefit compared to other suppliers, where you must settle for integrated tooling from the same supplier. The AppExchange features all kinds of apps capable of supporting your processes (recruitment, sales, marketing, finance, etc.). It is often the case that these apps have been developed by experts in the relevant fields. Consider Data loader (data import), Mailchimp (e-mail marketing), Grow promoter (NPS research) and Ebsta (integration with Gmail) for example.  Lead Management Salesforce.com can help your company track your leads from clicks, that is from being a prospect to closing the deal, while continually optimizing your campaigns across every channel. Make smarter decisions about where to invest your marketing money, thereby reducing financial loss in your company. Reports Our CRM analytics software keeps you updated with customized sales forecasting reports that you can build with ease. Just drag and drop the fields, filters, groupings, and charts that you want, and get an immediate real-time view. Salesforce can generate 1000+ reports in less than a second with just a few clicks on your data which can save your company from quite several stress and time wastage. Contact Management You can have a complete view of your customers, including activity history, key contacts, customer communications, and internal account discussions. Gain insights from popular social media sites such as Facebook, Twitter, LinkedIn, and YouTube all right within Salesforce. Get an accurate view of your entire business with comprehensive forecasts. See a complete view of your entire pipeline and your business, and act where necessary. Provide rapid updates to help management make decisions. Then easily apply your judgment to forecasted amounts at the rep, period, and summary levels. You can also view details about any previous adjustments that you or your team provided while leaving the underlying opportunity data intact.

Blogs

TOP 7 BIG DATA ANALYTICS TOOLS IN 2020

Big Data Analytics tools are generally used to provide substantial analysis of a large set of data. It helps to find market insights, trends, customers’ preferences, and diverse information. These tools vary in features, efficiency, and complexity. In this article, I have compiled the top 7 data analytics tools this year. Here are the top 7 Big Data analytics tools in 2020. 1.  Tableau Tableau is a well- known software in the field of data analysis and it’s a good choice for folks with no knowledge of data science, working in businesses across organizations. Although may seem similar to an excel spreadsheet, it has more features and advantages over excel. In Tableau, no more chunk of boring data with its VizQL data visualization technology. Tableau users enjoy the benefit to reuse existing skills in the Big Data(context) settings. It uses standardized SQL to query and interface with Big Data systems thereby making it easy for enterprises to use an existing database to get insights. Tableau allows quick data lookup and analysis by incorporating “Hyper” which is its memory data engine.  You can read more about Tableau here. 2. Zoho Analytics  One of the notable features of Zoho Analytics is its ease of use. You do not need the help of an IT or data scientist expert to gather information from data. This software has both a spreadsheets style interface and an easy drag and drop interface. Zoho is also by far, one of the top data analytics tools in 2020 In a world of various data sources, Zoho Analytics enables access to a wide array of data storage. Files in your local storage, several important business applications, cloud drives, databases, and custom-built applications are all included. If you are searching for an analytical tool that will give you easy and accessible data insight to every employee/worker in your business, then Zoho is a good fit for you. 3.Microsoft Power BI  A characteristic feature of Microsoft power BI is its ease of use. It has been a choice for analyst companies in the business intelligence field. Over the years, the major differentiator of Power BI is its integration with the Azure Data Lake storage for analysis of advance big data.  It is one of the top big data analytics tools for a while now. 4. Cloudera  A distinguishing feature of Cloudera is its close ties with the core Hadoop Big Data. It has an intensive understanding and key expertise in Hadoop. Cloudera is a good option for businesses who want to create and process predictive analysis models with several integrated tools.  It is one of the top data analytics tools this year. 5. SAS Visual Analytics  SAS Institute has been in the analytic marketplace for a long while. It is recognized for deep competence in data analysis. It is suitable for business intelligence and data reports. 6. Oracle Analytics Cloud   Oracle Analytics Cloud is also a big data analytics tool. It is known for its self-service in Big Data Analysis on a consumption usage model. Businesses who are familiar with Oracle tools will likely be the ones most interested in Analytics Cloud offering. Oracle Analytics prides itself on its ability to bring together multiple data sources. 7.Hitachi Vantara Pentaho  Although Hitachi would most likely not be linked with Big Data, its open-source nature is a major differentiator and strength. Hitachi is a good option for a business that has several types of data and big data sources. Pentaho users enjoy the ability to ingest and blend data quickly from different sources.

Blogs

Why SQL Is An Important Skill To Learn

SQL is something you probably have come across in several articles or on social media. The first time I heard about SQL was from a friend’s retweet on Twitter. Today, I want to share with you an educative article on SQL, and why SQL is an important skill for you to learn. Here are some of the things I am going to be covering in this article What is SQL? Difference between a Programming language and query language Who can learn SQL? What is MYSQL? Jobs that require SQL How long will it take to learn SQL? The three-letter abbreviation SQL, pronounced “ess-que-el” or “see-kwell” is quite a hot skill to learn. SQL means Structured Query Language. Yep, you got that right. It is not a programming language, at least not exactly. It is a “query language”. What does a query language mean? Simply put, a query language is a computer programming language that retrieves information from a database. So, SQL is a query language that is used to communicate with the database. It is used to update or retrieve data from a database. If you are a beginner, you should consider learning SQL as it is much easier than programming language like Java, PHP, Java, C++. What is the difference between a Query Language and Programming Language? A programming language is a language used by humans to give instructions to a computer; the steps to take in solving a problem. A query language, on the other hand, is a language used to manipulate data. Who can learn SQL? Often, a lot of people say, “I can’t code, I don’t think I can learn SQL. I’m not a techie, how can I understand SQL? Luckily, anyone, anybody can learn SQL. You don’t have to know any programming language before you can learn SQL.  No technical skill is required. It’s a “come as you are” language. No prerequisite for learning. What is MYSQL? It is a relational database management system used to manage databases. It is an open-source software. This means it is free to use and essential for web developers because several applications and web are built on databases. What does MYSQL do? Here’s an illustration. A movie program such as Netflix, stores and transmit movies, documentaries, TV shows and anime on different devices. You can search easily for movies by using parameters like movie name, genre, actor, director, and others. Apps like that need a software to manage their SQL database. Here are some reasons why SQL is an important skill to learn. It is a highly demanded skill SQL is one of the languages used by Web developers, desktop developers, DevOps, and data analysts. Did you know that it’s not only used by tech companies?  According to Dice; one of the most popular job posting sites, listed SQL as the most sought-after skills by employers. Even more than Python or R. Isn’t that surprising? That shows how useful and relevant SQL is to companies. It is an important skill that everyone should learn, as long as they can. It is used widely  SQL is used everywhere, as long as there is a database account to manage. If you are considering a career in data science or analytics, then you should learn SQL. Several big tech companies such as Airbnb, Facebook, Amazon, Netflix, Twitter, Google, and lots more use SQL to query data and carry out an analysis. Are you still wondering why SQL is such an important skill to learn? SQL is easy to learn One thing I can assure you when learning SQL is that you will find it interesting. Why? Unlike programming languages, it is written in the English language so everyone can understand it. If you understand and can write basic English language, then you are good to go.  Luckily, several database engines can work well with every SQL code. You can work across all relational databases when you learn SQL. There are also several learning platforms to pick it up. High salary scale How much does a SQL developer take home?  According to Glassdoor, a SQL developer earns an average of $81,622 annually. That’s a good income. Right? Now that you’ve learned why you should learn SQL. What next? You can access several resources that teach SQL online including free and paid. Some courses at the university can also give you a profound knowledge of the language. You can also enroll in paid online training such as Cndro’s SQL class. It provides you with real-life projects and one-on-one training support. Click here to enroll now. Jobs that require SQL Data Analyst: Since data analysts work with data daily, SQL is a required skill for them.  It is easy to learn and understand. SQL helps data analysts gain access directly to large sets of data in the database without having to duplicate data into other applications. Data Scientist: Just like data analysts, data scientists also deal with data daily, even in larger volumes and gather it at a higher speed. Because SQL integrates well with programming languages like Python and R, you will be able to communicate your data easily and understandably to your company. Database Administrator: The database administrator ensures that data is stored and organized properly. They also generate different reports by querying the database and manage data replication. Back-end Developer: Back-end developers manage the internal workings of web applications. They are behind everything that happens before it gets to your browser. A typical setup for a backend is a web server, an application, and a database. Product Managers: They need to have an in-depth understanding of their products. How will they do that? By using data to take an audit of their product’s performance. Data doesn’t lie, they say. Mobile App Developers Android app developers have been using SQLite for over 20 years. They used it mainly for projects that need to be stored on a device. SQL powers this embedded database; SQLite. Marketers: If you are a marketer, you have to be data-driven. Why? Because you won’t always have the attention of the analysts or developers to explain the reports to you. You will be more productive and help your business if you can

Blogs

Encrypt s3 Bucket Using Server-Side Encryption

Data encryption is basically the process of securing information in a way that it can only be accessed by a specific key. In this article, I am going to show you how to encrypt your s3 bucket using the s3 server-side encryption (SSE-S3). You can choose to create a new bucket, or encrypt an already created bucket. Another method of encrypting your data on AWS is through the Key Management Service. It is somewhat different from server-side encryption. You can find a step-by-step walk-through on it here When using server-side encryption, you are basically encrypting your data with a default manage key that will be generated by Amazon Web Services (AWS). In this post, I will walk you through server side encryption of your s3 bucket. I will also show you how to encrypt your data before uploading it to the bucket. Let’s get right to it Server-side Encryption of S3 bucket 1. Sign in to AWS Console (https://console.aws.amazon.com/console/home) 2. Drop down the “Services” tab and select “S3” in the “Storage” menu. An interface will be displayed to you where you can select the s3 bucket you want to encrypt; or create a new s3 bucket For the purpose of this article, I will be creating a new s3 bucket. 3. Click on the “Create bucket” button in the top right corner. 4. Input your bucket name and region. I have named our sample bucket as “blogtestbucket”. 5. After successfully creating a new bucket, select the “Bucket details” button in the top right corner. This will take you to your bucket page. There you will find the “Overview”, “Properties”, “Permissions”, “Management”, and “Access Points” tab. 6. Select the “Properties” tab and click on “Default encryption”. 7. Next, select the “AES-256” option. This is the option to use server-side encryption with S3-managed keys for your bucket. Click “Save” to successfully encrypt your s3 bucket using server-side encryption. Your “Default encryption” tab should look like the image below when you are done. Note: If you want to encrypt an already created bucket, skip steps 3 to 5. Proceed from step 6. Server-side Encryption of Data Just in case you want to encrypt your data using server-side encryption before uploading it to your s3 bucket, follow the following steps. It’s quite easy. 1. Select the s3 bucket you want to upload data into, and as expected, select the “Upload” button. 2. Select the file(s) you want to upload, and click “Next”. 3. Scroll down to the Encryption section and select the “Amazon s3 master-key” option. 4. Complete the uploading process and you are all set. If you found any aspect of this walk-through helpful, you can share with any of the buttons below. Questions are welcomed in the comments section.

Blogs

Encrypt Data Using AWS Key Management Service

WS Key Management Service (KMS) is an Amazon Web Services product that allows administrators to create, delete, and control keys that encrypt data stored in AWS databases and products. In this article, I am going to walk you through how to encrypt data using the AWS Key Management Service. We’ll be creating an encryption key, encrypting s3 bucket using KMS, and encrypting data using KMS. When encrypting your s3 bucket data in AWS, you can either use the AWS Server-Side encryption or go through the Key Management Service. To know how to carry out server-side encryption, click here. Creating a key The first step to encrypting your S3 bucket or your data using AWS KMS is to create your encryption key. Let me walk you through this process real quick. 1. Sign in to your AWS Console. (https://console.aws.amazon.com/console/home). 2. Drop down the “Services” tab. Select “Key Management Service”. It can be found in the “Security, Identity & Compliance” menu. Here’s what I mean: AWS Console >> Services >> Key Management Service 3. A new page will be displayed where you can select the “Create a key” button to create your encryption key. 4. Next up is to configure your key. Select the type of key that you want to create. You can choose to create a symmetric key type, i.e, a single encryption key. The other option is an asymmetric key type that contains a pair of a public and private key. For this article, we’ll be using a symmetric key type. 5. Finally, enter an alias and a description for your key. The description is totally optional Encrypting s3 bucket using KMS Now that you have created your key, you can proceed to encrypting your data with KMS. To encrypt an entire s3 bucket in AWS with KMS, follow these steps: 1. Drop down the “Services” tab in your AWS console and select “S3” in the “Storage” menu. 2. Select the S3 bucket you want to encrypt, or create a new one as the case may be. 3. This will take you to your bucket page. There you will find the “Overview”, “Properties”, “Permissions”, “Management”, and “Access Points” tab. Select the “Properties” tab and click on “Default encryption”. 4. Select the AWS-KMS option, select the key you created earlier and “Save”. This will encrypt your bucket with the Key Management Service. Your “Default encryption” tab should look like the image below when you are done: Encrypting data using KMS If you want to encrypt data using KMS before uploading to your s3 bucket, follow these steps: 1. Select the s3 bucket you want to upload data into, and as expected, select the “Upload” button. 2. Select the file(s) you want to upload, and click “Next”. 3. Scroll down to the Encryption section and select the “AWS KMS master-key” option, and select the encryption key. 4. Complete the uploading process and you are all set. If you found any aspect of this walk-through helpful, you can share it with any of the buttons below. Questions are welcomed in the comments section.

Uncategorized

How to Conditionally Format an EXCEL/CSV file in Alteryx

Conditional formatting is a feature included in spreadsheet creation programs. It automatically applies formatting to a cell when the data in that cell meets a specific criteria. In this post, I will be sharing with you a video walkthrough on how to conditionally format an Excel or CSV file in Alteryx. Watch the video below:

Uncategorized

IF Statements in Python

Conditional Statements in Python are used to decide the flow of execution of a program or code in Python. It’s like telling your program, “Hey, do this particular thing if it meets this condition, or if it doesn’t”. In Python, conditional statements are handled with “IF”. In this article, I am going to walk you through the different IF statements in Python, using a practical approach. Here’s what I mean; I am not just going to give long definitions of the different types of IF statements in Python. We will see how they all work by building an online grading system for test scores with Python. It is important to note that IF Statements in Python works together with Python’s logical operators: AND, OR. Let’s get right to it. Remember, we are going to be learning these IF statements while building an online grading system for students’ test scores. The first thing to do is to launch your IDE. I am using the Jupyter notebook and I really recommend it. Jupyter notebook is something you get automatically when you download anaconda. Now, to writing code. testscore = input(“Please input your testscore:”) testscoreint = int(testscore) The above code is to present an interactive environment on the front-end so that the user/student can enter his/her score. Running the code above will return the image below: The student will input his/her test score here. Now that we have an interactive environment for the students, let us move on to applying the different types of IF statements to our mock grading system. One-way IF statement (IF) The one-way IF statement in Python is used to make single one-way decisions in your program. It is basically saying “if this is the situation, then do that.”. Let’s apply it to our mock online grading system to see how it works. if testscoreint>=70 and testscoreint<=100: print(“Congratulations, you scored ‘A'”) The code above is basically telling the program that if a student enters a score that is between 70 and 100, then the system should display the text “Congratulations, you scored an A”. Let’s put it to test. 1-way IF statement I tested it with a score of 87 because it is within the range of numbers specified in the condition. In a 1-way statement, there won’t be an output for values that do not meet the specified condition. Two-way IF Statement (ELSE) The 2-way IF statement leaves room for one alternative decision. “If it meets the requirements, do this. If it doesn’t, do this instead.” This is only possible with the addition of “ELSE”. Let me show you how it works. Here is our code: testscore = input(“Please input your testscore:”) testscoreint = int(testscore) if testscoreint>=70 and testscoreint<=100: print(“Congratulations, you scored ‘A'”) else: print(“Nice Work!”) This is following our first example, but this time there is an option for those whose test score is not between 70 and 100. This code is telling Python, “Hey, if it’s not between 70 and 100, print Nice Work.” This means that any score between 0 to 69 is “Nice Work”, which is not good enough for a standard grading system. I mean, 10 out of 100 is definitely not “Nice Work”” Multi-way IF Statement (ELIF) The multi-way IF statement is the most efficient of them all, and of course, it’s a bit more complicated. In the 2-way statement, an alternative decision is given. But, in the multi-way statement, 1 or more alternative conditions are provided for the program before a final alternative decision with “ELSE”. This is made possible with the addition of “ELIF”, a combination of ELSE and IF. Let’s get to the code so you can understand exactly what I mean testscore = input(“Please input your test score:”) testscoreint = int(testscore) if testscoreint>=70 and testscoreint<=100: print(“Congratulations, you scored ‘A'”) elif testscoreint>=60 and testscoreint<=69: print(“Nice Work, That’s a ‘B'”) elif testscoreint>=50 and testscoreint<=59: print(“Averagely good! It’s a ‘C'”) elif testscoreint>=40 and testscoreint<=49: print(“You have a ‘D’. Try harder”) else: print(“You failed, it’s an ‘F'”) The code above is saying the following things: If the score is between 70 and 100, display “Congratulations, you scored A” to the student. If it doesn’t meet the first condition, check if it meets the next one, if it’s between 60 to 69; or 50 to 59, etc. If it doesn’t meet any of the conditions specified, then go ahead and display the final alternate decision. Let’s see how the code works in the following examples: A score of 14 meets none of the specified conditions, hence Python prints the final alternative decision. That’s pretty much how an online grading system with python works. You can try the codes out with different values, switch up the conditions as you please, and so much more.

Scroll to Top