changing#1
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates a set of small Python example scripts, primarily by adding explanatory comments, minor formatting tweaks, and introducing several new beginner-focused example files (nested ifs, lambda, local/global scope, etc.).
Changes:
- Added/expanded educational comments across multiple existing scripts.
- Added new example scripts:
nested_if.py,local_ global.py,lambda_function.py,func_argument.py, andhello.py. - Minor cleanup of whitespace/formatting and a few comment edits.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| while_loop.py | Adds an f-string explanation comment above the infinite loop example. |
| switch case.py | Adds explanatory comments for the case _ default branch. |
| strings,methods,slicing.py | Minor comment cleanup and trailing newline. |
| nested_if.py | Adds new nested-if examples (driving eligibility and a login flow). |
| local_ global.py | Adds a new example demonstrating local vs global variables and global. |
| lambda_function.py | Adds a new lambda usage examples script. |
| input.py | Adds expanded explanatory comments about input types and printing. |
| if else.py | Minor formatting change to a chained comparison example. |
| hello.py | Adds a minimal “hello world” script. |
| functions.py | Adds a short pass statement example at the end. |
| function_overloading.py | Adds/adjusts comments around singledispatch and whitespace. |
| func_argument.py | Adds a new script demonstrating positional/default/keyword arguments. |
| for loop.py | Adds a small clarifying comment about range(). |
| f_string.py | Adds more f-string explanation/examples. |
| day 1.py | Adds a triple-quoted block intended as a multi-line comment example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+28
to
+29
| # f string is also used to format the string in python and | ||
| # it is more efficient than + operator to concatenate the string and variable. |
Comment on lines
+16
to
+17
| # if day is not 1, 2, 3, 4, or 5, this block will execute | ||
| # its just like else |
| # or by using single dispatch function | ||
|
|
||
|
|
||
| # or by using singled ispatch function |
Comment on lines
+9
to
+17
| #as age is string here suppose we take it in | ||
| # int(input(enetr your age:)) then we we will use commas instead | ||
| # of + to print the age because we cannot concatenate | ||
| # string and integer. | ||
|
|
||
| # if you want to use + then you have to do str(age) means | ||
| # again convert it into string to print | ||
| # because + can only concatenate string and string not | ||
| # string and integer. |
Comment on lines
+27
to
+28
| # we can also do print(int(gpa)+int(cgpa)) | ||
| # if gpa and cgpa are string type but it is not a good practice |
Comment on lines
+33
to
+45
| def describe_pet(name, animal_type, age): | ||
| print(f"{name} is a {animal_type} and is {age} years old") | ||
|
|
||
| # Positional | ||
| describe_pet("Max", "dog", 3) | ||
|
|
||
| # Keyword (order doesn't matter!) | ||
| describe_pet(animal_type="cat", name="Whiskers", age=5) | ||
| describe_pet(name="Buddy", age=2, animal_type="bird") | ||
|
|
||
| # Mix positional and keyword (positional must come first!) | ||
| describe_pet("Max", animal_type="dog", age=3) # ✅ Correct | ||
| # describe_pet(name="Max", "dog", age=3) # ❌ SyntaxError! |
| @@ -0,0 +1,24 @@ | |||
| # lambda then variable name then : then expression | |||
Comment on lines
+9
to
+12
| """hello how are you my gng | ||
| i am fine and you | ||
| i am also fine""" | ||
| # and these comments are multiple line comments |
Comment on lines
+96
to
+120
| username = input("Enter username: ") | ||
| password = input("Enter password: ") | ||
| account_locked = False | ||
| login_attempts = 0 | ||
|
|
||
| if username == "admin": # Level 1 | ||
| print("Username found") # Level 1 | ||
|
|
||
| if account_locked: # Level 2 | ||
| print("Account is locked") # Level 2 | ||
| else: # Level 2 | ||
| if password == "admin123": # Level 3 | ||
| print("Login successful!") # Level 3 | ||
|
|
||
| if login_attempts > 3: # Level 4 | ||
| print("Warning: Multiple failed attempts") # Level 4 | ||
| else: # Level 3 | ||
| print("Incorrect password") # Level 3 | ||
| login_attempts += 1 # Level 3 | ||
|
|
||
| if login_attempts >= 5: # Level 4 | ||
| print("Account locked due to too many attempts") # Level 4 | ||
| account_locked = True # Level 4 | ||
| else: # Level 1 | ||
| print("Username not found") # Level 1 No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.