- Notifications
You must be signed in to change notification settings - Fork 975
Practice python#39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Practice python #39
Changes from all commits
af75779672e459a351798127a5e41c4bceaf417f40db061aa6c0ba7b08b4cd03cd01c669a53186611f3a55ef2c95bfdd0588b38b433a32bf190ef2364f97d10c28b194c604bde5c9f71c9f7dba5ca341438db8fd9e85255df9b7ef27bfb71f775276306026ca750d28b3194bcc936457902a6c1aa50bdfc535111File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| a = (1,45,342,3424,False, "Rihan", "Nihal") | ||
| print(a) | ||
| print(type(a)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| a-(1,22,3,45,False,"RIhan") | ||
| print(a) | ||
| no = a.count(45) | ||
| print(no) | ||
| i=a.index(3424) | ||
| print(i) | ||
| print(len(a)) | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| a = 23 | ||
| aaa = 435 | ||
| Rihan = 34 | ||
| sameer = 45 | ||
| _samerr = 34 | ||
| # @sameer = 56 # Invalid due to @ symbol | ||
| # s@meer # Invalid due to @ symbol |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import os # 📦 Import the built-in 'os' module to interact with the operating system | ||
| # 📂 Select the directory whose contents you want to list | ||
| directory_path = '/' | ||
Comment on lines
+1
to
+4
CopilotAI | ||
| # '/' means the root directory (top-most folder of the file system) | ||
| # On Windows, this may raise an error. Example alternative: 'C:\\' or '.' (current folder) | ||
| # 🧠 Use the os module to list the directory contents | ||
| contents = os.listdir(directory_path) | ||
| # os.listdir(): | ||
| # - Reads all files and folders inside the given directory | ||
| # - Returns the result as a Python list of strings | ||
| # - Each string is a file or folder name | ||
| # - It does NOT give file sizes or details, only names | ||
| # 🖨️ Print the contents of the directory | ||
| print(contents) | ||
| # print(): | ||
| # - Displays the list of files and folders on the screen | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,121 +1,14 @@ | ||
| # The Ultimate Python Course | ||
| ## Python Learning & Practice Repository | ||
| Welcome to [**The Ultimate Python Course!**](https://youtu.be/UrsmFxEIp5k) | ||
| This repository is forked from CodeWithHarry's Python course. | ||
| I use it to learn Python by rewriting examples, | ||
| adding my own practice, notes, and small improvements. | ||
| This course is designed to take you from a beginner to an advanced Python programmer. The repository contains all the source code, projects, problem sets, and additional resources to supplement your learning. | ||
| This is a part of my video The Ultimate Python Couse. Refer to this [video](https://youtu.be/UrsmFxEIp5k) to watch my Python course | ||
| ### What I am doing here | ||
| - Rewriting course code in my own way | ||
| - Adding comments and explanations | ||
| - Creating small practice programs | ||
| - Learning Git and GitHub workflow | ||
| ## Table of Contents | ||
| - [The Ultimate Python Course](#the-ultimate-python-course) | ||
| - [Table of Contents](#table-of-contents) | ||
| - [Introduction](#introduction) | ||
| - [Chapters](#chapters) | ||
| - [Projects](#projects) | ||
| - [Problem Sets](#problem-sets) | ||
| - [Additional Resources](#additional-resources) | ||
| - [How to Use This Repository](#how-to-use-this-repository) | ||
| ## Introduction | ||
| This repository is part of **The Ultimate Python Course** created by [CodeWithHarry](https://www.codewithharry.com/). The course aims to provide a comprehensive guide to learning Python programming. | ||
| ## Chapters | ||
| The course is divided into several chapters, each focusing on different aspects of Python programming: | ||
| - **Chapter 1: Modules, Comments & pip** | ||
| - Writing the first Python program | ||
| - Understanding modules | ||
| - Using pip for package management | ||
| - Using Python as a calculator | ||
| - Comments in Python | ||
| - **Chapter 2: Variables and Data Types** | ||
| - Defining variables | ||
| - Different data types in Python | ||
| - Rules for choosing an identifier | ||
| - Operators in Python | ||
| - Using `type()` function and typecasting | ||
| - `input()` function | ||
| - **Chapter 3: Strings** | ||
| - String slicing | ||
| - Slicing with skip values | ||
| - String functions | ||
| - Escape sequence characters | ||
| - **Chapter 4: Lists and Tuples** | ||
| - List indexing | ||
| - List methods | ||
| - Tuples in Python | ||
| - Tuple methods | ||
| - **Chapter 5: Dictionary & Sets** | ||
| - Properties of dictionaries | ||
| - Dictionary methods | ||
| - Sets in Python | ||
| - Properties and operations on sets | ||
| - **Chapter 6: Conditional Expression** | ||
| - `if`, `else`, and `elif` statements | ||
| - Relational and logical operators | ||
| - **Chapter 7: Loops in Python** | ||
| - `while` loop | ||
| - `for` loop | ||
| - `range()` function | ||
| - `for` loop with `else` | ||
| - Break, continue, and pass statements | ||
| - **Chapter 8: Functions & Recursions** | ||
| - Defining and calling functions | ||
| - Recursion in Python | ||
| - **Chapter 9: File I/O** | ||
| - Reading and writing files | ||
| - Working with directories | ||
| - **Chapter 10: Object-Oriented Programming** | ||
| - Classes and objects | ||
| - Methods and attributes | ||
| - **Chapter 11: Inheritance & More on OOPs** | ||
| - Inheritance | ||
| - Polymorphism | ||
| - Operator overloading | ||
| - **Chapter 12: Advanced Python 1** | ||
| - Newly added features in Python | ||
| - Walrus operator | ||
| - Advanced type hints | ||
| - Match case | ||
| - Dictionary merge & update operators | ||
| - Exception handling enhancements | ||
| - Global keyword and enumerate function | ||
| - List comprehensions | ||
| - **Chapter 13: Advanced Python 2** | ||
| - Virtual environments | ||
| - Lambda functions | ||
| - String methods: `join` and `format` | ||
| - Functional programming: `map`, `filter`, and `reduce` | ||
| ## Projects | ||
| - **Project 1: Snake Water Gun Game** | ||
| - A fun and interactive game where the player competes against the computer in a variation of Rock-Paper-Scissors. | ||
| - **Project 2: Guess The Number** | ||
| - A guessing game where the player tries to guess a randomly generated number within a certain range. | ||
| - **Mega Project 1: Jarvis Virtual Assistant** | ||
| - A voice assistant application capable of performing various tasks such as playing music, and providing information. | ||
| - **Mega Project 2: AI AutoReply Bot** | ||
| - An AI-based bot designed to automatically reply to messages, enhancing communication efficiency. | ||
| ## Problem Sets | ||
| Each chapter contains problem sets to test your understanding and to practice coding. The problem sets include various challenges and exercises relevant to the chapter's content. | ||
| ## Additional Resources | ||
| - **[Download the Handbook](https://github.com/CodeWithHarry/The-Ultimate-Python-Course/blob/main/The%20Ultimate%20Python%20Handbook.pdf)** | ||
| - **[Download the Handwritten Notes](https://www.codewithharry.com/notes)** | ||
| - **[Download the Ultimate Python Cheatsheet](https://www.codewithharry.com/blogpost/python-cheatsheet/)** | ||
| ## How to Use This Repository | ||
| 1. **Clone the repository** to your local machine using: | ||
| ```sh | ||
| git clone https://github.com/CodeWithHarry/The-Ultimate-Python-Course.git | ||
| ``` | ||
| 2. **Navigate through the chapters** to find the relevant lessons and code examples. | ||
| 3. **Complete the problem sets** provided at the end of each chapter to solidify your understanding. | ||
| 4. **Work on the projects** to apply your knowledge in real-world scenarios. | ||
| ### Status | ||
| Ongoing learning (updated weekly) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import os | ||
| #select the directory whose content you wnat to list | ||
| directory_path = '/' | ||
| #use the os module to list the directory content | ||
| contents = os.listdir(directory_path) | ||
| #print the contents of the directory | ||
| print(contents) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| a = int(input("Enter your age: ")) | ||
| # If else statement | ||
| if(a>=18): | ||
| print("You are above the age of consent") | ||
| print("Good for you") | ||
| else: | ||
| print("You are below the age of consent") | ||
| print("End of Program") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| a = 12 | ||
CopilotAI | ||
| b = 34 | ||
| c = 56 | ||
| average =(a + b + c)/3 | ||
| print(average) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # BMI 🏋️♀️ | ||
CopilotAI | ||
| weight = 92.3 | ||
| height = 1.86 | ||
| bmi = weight / (height**2) | ||
| print(bmi) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,6 @@ | ||||||
| d={} #empty dictonary | ||||||
| marks= { | ||||||
| "Rihan":100, | ||||||
| "Nihal":99, | ||||||
| } | ||||||
| print(marks["Rihan:"]) | ||||||
CopilotAI | ||||||
| print(marks["Rihan:"]) | |
| print(marks["Rihan"]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| file = file.open(file.txt) | ||
| open= file.read() | ||
| print(data) | ||
| file.close() | ||
| # output- hello world |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| name = input("enter your name") | ||
| print(f"Good morning,{name}") | ||
Comment on lines
+1
to
+2
CopilotAI | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||||||||||||||||
| def inch_to_cm(inch) | ||||||||||||||||||
| return inch * 2.54 | ||||||||||||||||||
| n = int(input('enter value in inches: ")) | ||||||||||||||||||
| print(f"the corresponding vlaue in cms is (inches_to_cms(n)}") | ||||||||||||||||||
Comment on lines
+1
to
+4
CopilotAI | ||||||||||||||||||
| definch_to_cm(inch) | |
| returninch*2.54 | |
| n=int(input('entervalueininches: ")) | |
| print(f"the corresponding vlaue in cms is (inches_to_cms(n)}") | |
| definch_to_cm(inch): | |
| returninch*2.54 | |
| n=int(input("enter value in inches: ")) | |
| print(f"the corresponding vlaue in cms is {inch_to_cm(n)}") |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,6 @@ | ||||||||||||||||||||||||||
| purchase list = ["Apples","Orange",5,43.5,False,"Aakash","ROhan"] | ||||||||||||||||||||||||||
| prints(friends[0]) | ||||||||||||||||||||||||||
| friends[0]="Grapes" #unlike list strings are mutable | ||||||||||||||||||||||||||
| print(friends[0]) | ||||||||||||||||||||||||||
| print(friends[1:4]) | ||||||||||||||||||||||||||
Comment on lines
+1
to
+6
CopilotAI | ||||||||||||||||||||||||||
| purchaselist= ["Apples","Orange",5,43.5,False,"Aakash","ROhan"] | |
| prints(friends[0]) | |
| friends[0]="Grapes"#unlike list strings are mutable | |
| print(friends[0]) | |
| print(friends[1:4]) | |
| purchase_list= ["Apples","Orange",5, 43.5,False,"Aakash","ROhan"] | |
| print(purchase_list[0]) | |
| purchase_list[0]="Grapes"# unlike list strings are mutable | |
| print(purchase_list[0]) | |
| print(purchase_list[1:4]) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||
| candidates = ["John cena","undertaker","Roman Reings",5,4.45,True] | ||||||
| prints(candidates) | ||||||
CopilotAI | ||||||
| prints(candidates) | |
| print(candidates) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| This folder contains my own Python practice, | ||
| rewritten examples, and experiments. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| a = 1 # a is an integer | ||
| b = 5.22 # b is a floating point number | ||
| c = "Harry" # c is a string | ||
| d = False # d is a boolean variable | ||
| e = None # e is a none type variable |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # My Data Analysis Practice: Loops | ||
| # This script shows how to process data lists using loops. | ||
Comment on lines
+1
to
+2
CopilotAI | ||
| def analyze_data(): | ||
| # --- PART 1: The 'For' Loop (Iterating through an Array/List) --- | ||
| # Scenario: I have a list of daily sales figures. I want to print each one. | ||
| print("1. Reading Daily Sales Data:") | ||
| daily_sales = [150, 200, 350, 400, 500] | ||
| # "sale" is a variable that holds one number at a time from the list | ||
| for sale in daily_sales: | ||
| print("Processing sale amount: $", sale) | ||
| print("-" * 30) | ||
| # --- PART 2: Filtering Data (Loop with Condition) --- | ||
| # Scenario: I only want to count days where sales were high (above 300). | ||
| print("2. Filtering High Sales (> 300):") | ||
| count = 0 | ||
| for sale in daily_sales: | ||
| if sale > 300: | ||
| print("Found high sale:", sale) | ||
| count = count + 1 | ||
| print("Total high revenue days:", count) | ||
| print("-" * 30) | ||
| # --- PART 3: The 'While' Loop (Data Cleaning) --- | ||
| # Scenario: removing '0' or bad data until the list is clean. | ||
| print("3. Cleaning Data (Removing Zeros):") | ||
| raw_data = [10, 0, 50, 0, 20] | ||
| # While '0' exists inside the raw_data list, remove it | ||
| while 0 in raw_data: | ||
| raw_data.remove(0) | ||
| print("Removed a zero... Current data:", raw_data) | ||
| print("Final Cleaned Data:", raw_data) | ||
| print("-" * 30) | ||
| # --- PART 4: Break and Continue --- | ||
| # Scenario: Searching for a specific error value (like -1). | ||
| print("4. searching for Errors:") | ||
| dataset = [12, 45, -1, 60, 100] | ||
| for value in dataset: | ||
| if value == -1: | ||
| print("Error found! Corrupted data detected. Stopping analysis.") | ||
| break # Stops the loop completely | ||
| print("Checking value:", value) | ||
| # Run the analysis function | ||
| if __name__ == "__main__": | ||
| analyze_data() | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pyjokes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # print("printing jokes") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # this prints a random jokes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| joke=pyjokes.getjokes() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(jokes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+6
to
+7
CopilotAI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| joke=pyjokes.getjokes() | |
| print(jokes) | |
| joke=pyjokes.get_joke() | |
| print(joke) |
CopilotAIJan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module 'pyjokes' imports itself.
| importpyjokes | |
| # print("printing jokes") | |
| # this prints a random jokes | |
| joke=pyjokes.getjokes() | |
| print(jokes) | |
| importrandom | |
| # print("printing jokes") | |
| # this prints a random jokes | |
| _JOKES= [ | |
| "Why do Python developers wear glasses? Because they can't C.", | |
| "There are only 10 kinds of people in this world: those who know binary and those who don't.", | |
| "A programmer walks into a bar and orders 1.000000119 beers.", | |
| ] | |
| defgetjokes(): | |
| """Return a random joke from the local joke list.""" | |
| returnrandom.choice(_JOKES) | |
| joke=getjokes() | |
| print(joke) |
CopilotAIJan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print statement may execute during import.
| joke=pyjokes.getjokes() | |
| print(jokes) | |
| defmain(): | |
| joke=pyjokes.getjokes() | |
| print(joke) | |
| if__name__=="__main__": | |
| main() |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| name="Rihan" | ||||||
| print(name[0:3]) | ||||||
| print(name[-4:1]) | ||||||
CopilotAI | ||||||
| print(name[-4:1]) | |
| print(name[-4:-1]) |
Uh oh!
There was an error while loading. Please reload this page.
CopilotAIJan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 1 uses
a-(...)which performs subtraction instead of creating a tuple, soais never assigned and the rest of the file will fail. Also,a.index(3424)will raiseValueErrorbecause3424is not present in the tuple values shown.