Sum-Positive

Wed 12 November 2025
def sum_positives(lst):
    positive_sum = sum(x for x in lst if x > 0)
    print("Sum of Positive Numbers:", positive_sum)

# Example usage
sum_positives([-1, 2, 3, -4, 5])
Sum of Positive Numbers: 10
def shift_list(lst, k):
    k = k % len(lst)  # Handle shifts larger than list length
    shifted = lst[-k:] + lst …

Category: python-basics

Read More

Switch-Statement

Wed 12 November 2025
#  created : 20250321
#  https://www.scientecheasy.com/2022/11/switch-statement-in-python.html/
#  Implementing Switch Statement in Python using If-Elif-Else
city = 'd' # Initialize the variable.
if city == 'm':
    print('Mumbai')
elif city == 'd':
    print('Dhanbad')
elif city == 'c':
    print('Chennai')
elif city == 'r':
    print('Ranchi')
else:
    print('No city')
Dhanbad
# Implementing Switch Statement …

Category: python-basics

Read More

Ternary-Operator

Wed 12 November 2025
#  created : 20250113
#  https://www.scientecheasy.com/2022/10/ternary-operator-in-python.html/
#  Ternary Operator in Python
x =  10 
y = 20 


if(x > y):
    msg = 'Hello'
else:
    msg = 'Goodbye'
print('Hello' if True else 'Goodbye') 
print('Hello' if False else 'Goodbye') 
Hello
Goodbye
x, y = 20, 40
z = 20 if (x > y) else …

Category: python-basics

Read More

Typing-Module

Wed 12 November 2025
#  created : 20251112
# https://stevejoe1412.gitbook.io/ssn/python-subtopics/1.-typing-module
from typing import List

def sum_of_integers(numbers: List[int]) -> int:
    return sum(numbers)

print(sum_of_integers([1, 2, 3]))  # Output: 6
6
from typing import Optional

def greet(name: Optional[str] = None) -> str:
    if name:
        return f"Hello, {name}!"
    return "Hello …

Category: python-basics

Read More

User-Defined-Functions

Wed 12 November 2025
#  created : 20250321
#  https://www.scientecheasy.com/2022/12/user-defined-functions-in-python.html/
# Syntax of User defined Function
# def function_name(parameter_list): # function header
#     . . . . . .
#     body_of_the_function
#     . . . . . .
#     return <value(s)>
# user defined function definition
def greeting():
    print('Hello world!')
    print('Welcome to the world of the programming!')
# Function calling.
greeting()
Hello world!
Welcome to the world …

Category: python-basics

Read More

Username

Wed 12 November 2025
import re
def valid_username(username):
    if username[0].isdigit():
        return False
    if len(username) > 15:
        return False
    return True

usernames_input = input("Enter usernames separated by commas: ")

usernames = usernames_input.split(',')

for username in usernames:
    username = username.strip()  
    print(f"Username: {username} -> Valid")
Enter usernames separated by commas:  jerin,dass


Username: jerin …

Category: python-basics

Read More

Variables-Python

Wed 12 November 2025
#  created : 20250112
#  https://www.scientecheasy.com/2022/09/variables-in-python.html/
#  variables in pyhton 
num = 20
print(id(num))
8910408
x = 20 
y = 50
z = 100
print(x);print(y);print(z)
20
50
100
phy = 89
chem = 86
maths = 90

marks_obtained = phy + chem + maths

mark = (marks_obtained * 100) / 300
print(mark …

Category: python-basics

Read More

Vowels-Str

Wed 12 November 2025

def count_vowels(s):
    vowels = "aeiouAEIOU"
    count = 0
    i = 0
    while i < len(s):
        if s[i] in vowels:
            count += 1
        i += 1
    print("Number of vowels:", count)

# Example usage
count_vowels("hello world")
Number of vowels: 3


Score: 0

Category: python-basics

Read More

While-Loop

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/while-loop-in-python.html/
count = 0
# Declare the while loop statement.
# Loop continuation condition expression that must ends with a colon (:).
while count < 5:
# Body of the loop.
    print('Hello Python') # This statement will execute as long as the condition is true.
    count += 1 …

Category: python-basics

Read More
Page 8 of 8

« Prev