Age-Calculator

Tue 01 July 2025
from datetime import datetime
def get_age(d):
    d1 = datetime.now()
    months = (d1.year - d.year) * 12 + d1.month - d.month

    year = int(months / 12)
    return year
age = get_age(datetime(1991, 1, 1))
age
33


Score: 5

Category: basics


Basic

Tue 01 July 2025
a = 5
b = 3
print(a + b)
8
print(a - b)
2
print(a * b)
15
print(a / b)
1.6666666666666667
num = 7
print("Even" if num % 2 == 0 else "Odd")
Odd
num = -10
if num > 0:
    print("Positive")
elif num < 0:
    print("Negative")
else:
    print("Zero")
Negative
a, b …

Category: basics

Read More

Basic2

Tue 01 July 2025
n = int(input("Enter a number: "))
sum = 0
for i in range(1, n+1):
    sum += i
print("Sum:", sum)
Enter a number:  2


Sum: 3
n = int(input("Enter a number: "))
count = 0
while n > 0:
    count += 1
    n //= 10
print("Digit count:", count)
Enter a number:  4


Digit …

Category: basics

Read More

Basic3

Tue 01 July 2025
def factorial(n):
    result = 1
    for i in range(2, n+1):
        result *= i
    return result

print(factorial(int(input("Enter number: "))))
Enter number:  62


31469973260387937525653122354950764088012280797258232192163168247821107200000000000000
def fib(n):
    if n <= 1:
        return n
    return fib(n-1) + fib(n-2)

n = int(input("Enter n: "))
for i in range …

Category: basics

Read More

Basic4

Tue 01 July 2025
def is_anagram(str1, str2):
    return sorted(str1.lower()) == sorted(str2.lower())

print("Anagram" if is_anagram(input("First string: "), input("Second string: ")) else "Not Anagram")
First string:  listen
Second string:  silent


Anagram
import string

def is_pangram(s):
    s = s.lower()
    return all(ch in s for ch in string.ascii_lowercase)

print …

Category: basics

Read More

Basic5

Tue 01 July 2025
with open("sample.txt", "w") as file:
    file.write("Hello, Stefina!\nThis is a sample file created by Python.\nWelcome to file handling!")
with open("sample.txt", "r") as file:
    content = file.read()
    print("File Content:\n")
    print(content)
File Content:

Hello, Stefina!
This is a sample file …

Category: basics

Read More

Stagergy 1

Tue 01 July 2025
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import classification_report, confusion_matrix
df = pd.read_csv('spam.csv', encoding='latin-1')[['v1', 'v2']]
df.columns = ['label', 'text']
df['label'] = df['label'].map({'ham': 0, 'spam': 1})
X_train, X_test …

Category: basics

Read More

Stragergy 2

Tue 01 July 2025
class Person:
    def greet(self):
        print("Hello, I am a person!")

p = Person()
p.greet()
Hello, I am a person!
class Person:
    def __init__(self, name):
        self.name = name

    def greet(self):
        print(f"Hi, I'm {self.name}")

p = Person("Alice")
p.greet()
Hi, I'm Alice
class Dog …

Category: basics

Read More

Stragergy3

Tue 01 July 2025
from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self): pass
from abc import ABC, abstractmethod

class Shape(ABC):
    def info(self):
        print("Shape info")

    @abstractmethod
    def area(self): pass
from abc import ABC, abstractmethod

class Appliance(ABC):
    def plug_in(self):
        print("Appliance plugged in")

    @abstractmethod
    def operate …

Category: basics

Read More

Test 1

Tue 01 July 2025
print("Hello World")
Hello World
def solve():
    try:
        n_input = input("Enter number of elements: ").strip()
        if not n_input:
            print("No input provided for number of elements.")
            return  
        n = int(n_input)  
        arr_input = input("Enter the array elements separated by space: ").strip()
        if not arr_input:
            print("No array elements provided.")
            return
        arr …

Category: basics

Read More
Page 1 of 2

Next »