Posts

Showing posts with the label python

Featured Posts

CS50 Python , Nutrition Facts Table

Image
Nutrition Facts: Python Practice for Beginners Nutrition Facts Table for Python Practice Welcome to this comprehensive guide for Python beginners! If you are learning how to work with lists, dictionaries, and loops, this post will help you build practical skills using a real-world example: nutrition facts for fruits. Understanding how to organize and manipulate data is a key part of programming, and this exercise will give you hands-on experience. Below is a sample table of fruits and their calorie values, formatted as a Python list of dictionaries. This structure is ideal for coding exercises, projects, or even building your own nutrition calculator. You can expand this list, add new fruits, or use it as a foundation for more advanced Python tasks. Python List of Dictionaries Example: fruits = [ {'name': 'Apple', 'calories': 130}, {'name': 'Avocado', 'calories': 50}, {'name': 'Banana', 'ca...

Open Source: The Invisible Engine of Your Daily Life

Image
 Open Source Software (OSS) Open Source Software (OSS)  What is Open Source Software (OSS)? Did you know that most of the technology you touch every single day isn't built behind locked doors? It’s powered by Open Source Software (OSS)—collaborative code that runs the world. From the phone in your pocket to the servers delivering this post, open source is everywhere. Here are a few heavy hitters you likely encounter daily: Android: The world’s most popular mobile OS, built on the solid foundation of the Linux Kernel. Apache (httpd) : The powerhouse of the internet. Nearly half of all websites globally serve their content via Apache. Social Media: Giants like Facebook and Instagram rely on massive OSS ecosystems to handle billions of interactions. Search Engines: When you "Google it," you're tapping into vast data farms running almost entirely on Linux. Weather Forecasting: 100% of the world's supercomputers—the ones predicting tomorrow's storm—run on Linux...

CS50 Python , Nutrition Facts Table

Image
Nutrition Facts: Python Practice for Beginners Nutrition Facts Table for Python Practice Welcome to this comprehensive guide for Python beginners! If you are learning how to work with lists, dictionaries, and loops, this post will help you build practical skills using a real-world example: nutrition facts for fruits. Understanding how to organize and manipulate data is a key part of programming, and this exercise will give you hands-on experience. Below is a sample table of fruits and their calorie values, formatted as a Python list of dictionaries. This structure is ideal for coding exercises, projects, or even building your own nutrition calculator. You can expand this list, add new fruits, or use it as a foundation for more advanced Python tasks. Python List of Dictionaries Example: fruits = [ {'name': 'Apple', 'calories': 130}, {'name': 'Avocado', 'calories': 50}, {'name': 'Banana', 'ca...

Python Course for Beginners – Learn to Code Online!

Image
 Complete Python Tutorial for Beginners: Step-by-Step Guide Python Online Course Why Learn Python? Are you ready to take your first step into the world of programming? Our Python Course for Beginners is designed to help you get started with coding in a fun, interactive, and easy-to-understand way. Whether you're completely new to programming or looking to expand your skill set, this online course will guide you through the essentials of Python, one of the most popular programming languages today. What You Will Learn: Basic Python Syntax & Fundamentals Variables, Loops, and Conditional Statements Functions and Data Structures Error Handling and Debugging Hands-on Coding Exercises and Projects Course Details: Format: Online via Google Meet Duration: 4 Weeks (8 Sessions) Schedule: Tuesdays and Thursdays, 7:00 PM - 8:30 PM (GMT) Cost: First Session Free! Then, $2 per hour. Don’t miss out on the opportunity to kickstart y...

15 Python Builtin-Functions You Need to Master as a Beginner

Image
  What are the important 15 Python Builtin-Functions You Should Know as a Beginner? 15 Python Builtin-Functions You Should Know What should you do as a Python Beginner? As a beginner in Python programming, it's important to familiarize yourself with the built-in functions that are essential for writing efficient and clean code. In this article, we will explore 15 Python built-in functions that you need to master in order to become proficient in the language. You will notice in the examples below - most of them at least - that we did not give you the output. Use the keyboard and apply them on a file, and let's call it main.py. You are a programmer now, not a normal person to read and watch only. And now, let's begin... 1. `print()`: This function is used to display the output of a program. It is a fundamental function that allows you to showcase results and information to the user. Example: print("Hello, World!") name = "Alice" print("Hello,", n...

Python : Generate Fake Data

Image
Generating Fake Data using Python and Faker Library Fake Data with Python Code Explanation and Usage: The provided code showcases how to generate fake data using Python and the Faker library. Here's a breakdown of the code and its usage: 1- Importing Dependencies: The code begins by importing the necessary modules: csv and Faker. The csv module is used to handle CSV file operations, while the Faker module is responsible for generating fake data. 2- Initializing Faker and Data List: The code creates an instance of the Faker class and initializes an empty list called data. This list will store the generated fake data to use it later in the file that we will create. 3- Generating Fake Data: A for loop is used to iterate "n" times, generating fake data for each iteration. The generated data is stored as a dictionary with keys representing the headers ('Name', 'Date of Birth', 'Email', 'Phone Number', 'Address') and values generated by ...

python | What is a for Loop?

Image
  Wider look over for Loops in Python for loop What are for Loops in Python? For loops allow you to iterate over a sequence of values. For example: for x in range(5):     print(x) outout: 0 1 2 3 4 Try it yourself Similar to if statements and while loops, for loops begin with the keyword for with a colon at the end of the line. Just like in function definitions, while loops and if statements, the body of the for loop begins on the next line and is indented to the right. But what about the stuff in between the for keyword and the colon? In our example, we’re using the range() function to create a sequence of numbers that our for loop can iterate over. In this case, our variable x points to the current element in the sequence as the for loop iterates over the sequence of numbers Keep in mind that in Python and many programming languages, a range of numbers will start at 0 , and the list of numbers generated will be one less than the provided value. So range(5) ...

CS50 Python | Week 6 | File I/O | Problem Set 6 | Scourgify

Image
Scourgify Pset 6 - scourgify The Challenge: The challenge involves cleaning and reformatting data from a CSV file containing student information. The data is initially structured with names and houses in a single column, separated by a comma and space, and enclosed in double quotes. The goal is to split the names into first and last names and create a new CSV file with columns for first name, last name, and house. The program, implemented in a file called scourgify.py, expects two command-line arguments: the name of an existing CSV file to read as input and the name of a new CSV file to write as output. The program uses the csv module, specifically DictReader and DictWriter, to handle the CSV operations. Additionally, the program performs error handling: If the user does not provide exactly two command-line arguments, the program exits with an error message: "Too few command-line arguments." If the specified input file cannot be read, the program exits with an error message: ...

How to use Python Virtual Environment - venv

Image
 Virtual Environment python virtual environment -venv What is Virtual Environment? Virtual Environment - we will call it (Virtualenv) - is an isolated environment where you can download packages away from python system packages. This article is about venv which is a built-in python package, and for windows users. How to simply use virtual environment? * To create a virtual Environment folder: >> python -m venv folder_name -> It's a good practice/common convention to add venv to the folder name to differentiate it from other folders. OR: >> python -m venv Exsisting_folder_name\new_venv_folder_name * To activate/move inside the Virual Envirnment folder: >> folder_name\Scripts\activate.bat OR: >> Exsisting_folder_name\new_venv_folder_name\Scripts\activate.bat - You will notice the name of the Virtual Environment folder in the beginning of the folder path.  - Now, you're working on an isolated folder which has only the default python global version ins...

Python LAB 2.8.1.4 Reading ints safely

Image
 Reading ints safely Reading ints safely Objectives improving the student's skills in defining functions; using exceptions in order to provide a safe input environment. Scenario Your task is to write a function able to input integer values and to check if they are within a specified range. LAB Sandbox The function should: accept three arguments: a prompt, a low acceptable limit, and a high acceptable limit; if the user enters a string that is not an integer value, the function should emit the message Error: wrong input, and ask the user to input the value again; if the user enters a number which falls outside the specified range, the function should emit the message Error: the value is not within permitted range (min..max) and ask the user to input the value again; if the input value is valid, return it as a result. Test data Test your code carefully. This is how the function should react to the user's input: Enter a number from -10 to 10: 100 Error: the value is not within per...

Python 2.5.1.10 LAB: Find a word!

Image
 Find a Word in a Combination of Characters Find a word game Objectives improving the student's skills in operating with strings; using the find() method for searching strings. Scenario Let's play a game. We will give you two strings: one being a word (e.g., "dog") and the second being a combination of any characters. Your task is to write a program which answers the following question: are the characters comprising the first string hidden inside the second string? For example: if the second string is given as "vcxzxduybfdsobywuefgas", the answer is yes; if the second string is "vcxzxdcybfdstbywuefsas", the answer is no (as there are neither the letters "d", "o", or "g", in this order) Hints: you should use the two-argument variants of the pos() functions inside your code; don't worry about case sensitivity. Test your code using the data we've provided. Test data Sample input: donor Nabucodonosor Sample output:...

Python 2.5.1.9 LAB: The Digit of Life

Image
 The Digit of Life The digit of life Life Path Number Calculator To know your life path number, You need to enter your birth date as numbers only to calculate your life path number. You should add the digits of the month, day, and year until you arrive at a single digit number. How digit of life  is calculated Let's see the lab question. Objectives improving the student's skills in operating with strings; converting integers into strings, and vice versa. Scenario Some say that the Digit of Life is a digit evaluated using somebody's birthday. It's simple - you just need to sum all the digits of the date. If the result contains more than one digit, you have to repeat the addition until you get exactly one digit. For example: 1 January 2017 = 2017 01 01 2 + 0 + 1 + 7 + 0 + 1 + 0 + 1 = 12 1 + 2 = 3 3 is the digit we searched for and found. Your task is to write a program which: asks the user her/his birthday (in the format YYYYMMDD, or YYYYDDMM, or MMDDYYYY - actually, the ...

Python 2.5.1.8 LAB: Anagrams

Image
 Anagrams Anagram Listen = Silent [1] An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.[1] For example, the word binary into brainy and the word adobe into abode. The original word or phrase is known as the subject of the anagram. Any word or phrase that exactly reproduces the letters in another order is an anagram. Now, lets see the lab question. Scenario An anagram is a new word formed by rearranging the letters of a word, using all the original letters exactly once. For example, the phrases "rail safety" and "fairy tales" are anagrams, while "I am" and "You are" are not. Your task is to write a program which: asks the user for two separate texts; checks whether, the entered texts are anagrams and prints the result. Note: assume that two empty strings are not anagrams; treat upper- and lower-case letters as equal; spaces are not taken into acc...

Python 2.5.1.7 LAB: Palindromes

Image
Python: Check If a String is a Palindrome Palindrome Objectives improving the student's skills in operating with strings; encouraging the student to look for non-obvious solutions. Scenario Do you know what a palindrome is? It's a word which look the same when read forward and backward. For example, "kayak" is a palindrome, while "loyal" is not. Your task is to write a program which: asks the user for some text; checks whether the entered text is a palindrome, and prints result. Note: assume that an empty string isn't a palindrome; treat upper- and lower-case letters as equal; spaces are not taken into account during the check - treat them as non-existent; there are more than a few correct solutions - try to find more than one. Test your code using the data we've provided. Test data Sample input: Ten animals I slam in a net Sample output: It's a palindrome Sample input: Eleven animals I slam in a net Sample output: It's not a palindrome So...

Python LAB 2.5.1.6 Improving the Caesar cipher

Image
 Improving the Caesar cipher Improving the Caesar Cipher Level of difficulty Hard Pre-requisites Module 1.11.1.1, Module 1.11.1.2 Objectives improving the student's skills in operating with strings; converting characters into ASCII code, and vice versa. Scenario You are already familiar with the Caesar cipher, and this is why we want you to improve the code we showed you recently. The original Caesar cipher shifts each character by one: a becomes b , z becomes a , and so on. Let's make it a bit harder, and allow the shifted value to come from the range 1..25 inclusive . Moreover, let the code preserve the letters' case (lower-case letters will remain lower-case) and all non-alphabetical characters should remain untouched. Your task is to write a program which: asks the user for one line of text to encrypt; asks the user for a shift value (an integer number from the range 1..25 - note: you should force the user to enter a valid shift value (don't give up and don't...