eng
competition

Text Practice Mode

Python most used code snippets

created Feb 17th, 09:24 by Kovid Tripathi


1


Rating

234 words
8 completed
00:00
python
# Python Typing Test.
with open('filename.txt', 'r') as file:
    content = file.read()
    print(content)
 
with open('filename.txt', 'w') as file:
    file.write("Hello, World!")
 
for item in my_list:
    print(item)
 
squares = [x ** 2 for x in range(10)]
 
def greet(name):
    return f"Hello, {name}!"
 
add = lambda x, y: x + y
 
try:
    result = 10 / 0
except ZeroDivisionError as e:
    print(f"Error: {e}")
finally:
    print("Execution completed")
 
def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True
 
my_dict = {"a": 1, "b": 2, "c": 3}
for key, value in my_dict.items():
    print(f"{key}: {value}")
 
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
     
    def greet(self):
        print(f"Hello, my name is {self.name} and I am {self.age} years old.")
 
my_list = [3, 1, 4, 1, 5, 9, 2]
my_list.sort()
print(my_list)
 
import os
import sys
import random
 
my_list = [1, 2, 3, 4, 5]
sub_list = my_list[1:4]
 
from datetime import datetime
current_time = datetime.now()
print(current_time)
 
text = "Hello, World!"
print(text.lower())
print(text.upper())
print(text[::-1])
 
count = 0
while count < 5:
    print(count)
    count += 1
 
age = 20
if age >= 18:
    print("Adult")
else:
    print("Minor")
 
with open('example.txt', 'w') as file:
    file.write("Hello, World!")
 
my_dict = {"name": "John", "age": 25}
my_dict["city"] = "New York"
my_dict.pop("age")
print(my_dict)
 
 

saving score / loading statistics ...