some more exercises

This commit is contained in:
authentik Default Admin 2026-05-26 07:36:20 +01:00
parent 50a871353c
commit 1d58d16a08
10 changed files with 179 additions and 0 deletions

7
life_in_weeks.py Normal file
View file

@ -0,0 +1,7 @@
def life_in_weeks(age):
weeks = 4680 - (age * 52)
print(f"You have {weeks} weeks left.")
life_in_weeks(20)

25
Ceasar-cipher.py Normal file
View file

@ -0,0 +1,25 @@
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input ("Type 'encode' to encrypt, type 'decode' to decrypt:\n").lower()
text = input("Type your message: \n").lower()
shift = int(input("Type the shift number: \n"))
def encrypt(original_text, shift_amount):
cipher_text = ""
for letter in original_text:
shifted_position = alphabet.index(letter) + shift_amount #7 -> 9
cipher_text += alphabet[shifted_position] # j
print(f"{cipher_text}")
encrypt(original_text = text, shift_amount = shift)

9
Function_input.py Normal file
View file

@ -0,0 +1,9 @@
def greet(name, person1):
print(f"the 1st print {name} ")
print(f"the 1st print {person1}")
greet(name="richard", person1="Dennis")

6
ValidData.py Normal file
View file

@ -0,0 +1,6 @@
users = [ {"name": "Alice", "email": "ALICE@Dell.com", "age": 30}, {"name": "Bob", "email": "", "age": 25}, {"name": "Carol", "email": "carol@dell.com", "age": -1}, {"name": "Dave", "email": "Dave@Dell.com", "age": 22}, ]
#output: [{'name': 'Dave', 'email': 'dave@dell.com', 'age': 22}, {'name': 'Alice', 'email': 'alice@dell.com', 'age': 30}]

10
count-words.py Normal file
View file

@ -0,0 +1,10 @@
import collections
text = "the quick brown fox jumps over the lazy dog the fox"
words = text.split()
char = text.replace(' ', '')
text_collect = collections.Counter(words).most_common(3)
print(f"words: {len(words)}, char: {len(char)} top 3: {text_collect}")
#my outpout: words: 11, char: 41 top 3: [('the', 3), ('fox', 2), ('quick', 1)]
#output: 11 caracteres: 43 top 3: [('the', 3), ('fox', 2), ('quick', 1)]ß

53
fizz.py Normal file
View file

@ -0,0 +1,53 @@
'''
FizzBuzz
You are going to write a program that automatically prints the solution
to the FizzBuzz game. These are the rules of the FizzBuzz game:
Your program should print each number from 1 to 100 in turn and include number 100.
But when the number is divisible by 3 then instead of printing the number it
should print "Fizz".
When the number is divisible by 5, then instead of printing the number it
should print "Buzz".`
And if the number is divisible by both 3 and 5 e.g. 15 then instead of the number it
should print "FizzBuzz"
e.g. it might start off like this:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
'''
for number in range(1, 100):
if number % 15 == 0:
print("FizzBuzz")
elif number % 3 == 0:
print("Fizz")
elif number % 5 == 0:
print("Buzz")
elif number % 7 == 0:
print("Buzz")
else:
print(number)

14
fizz_buzz_twist.py Normal file
View file

@ -0,0 +1,14 @@
import collections
for number in range(1, 101):
if number % 20 == 0:
print(collections.Counter(number))
elif number % 15 == 0:
print("FizzBuzz")
elif number % 3 == 0:
print("Fizz")
elif number % 5 == 0:
print("Buzz")
else:
print(number)

20
functions.py Normal file
View file

@ -0,0 +1,20 @@
# sky = "cloudy"
# def my_function():
# if sky == "clear":
# print("blue")
# elif sky == "cloudy":
# print("grey")
# print("Hello")
# print("Bye")
# my_function()
number = 0
while number < 100:
number += 1
print(number)

20
love_calculator.py Normal file
View file

@ -0,0 +1,20 @@
import collections
def calculate_love_score(name1, name2):
two_names = name1.replace(" ", "").lower() + name2.replace(" ", "").lower()
t = two_names.count("t")
r = two_names.count("r")
u = two_names.count("u")
e1 = two_names.count("e")
l = two_names.count("l")
o = two_names.count("o")
v = two_names.count("v")
e2 = two_names.count("e")
score_1 = t + r + u + e1
score_2 = l + o + v + e2
print(f"{score_1}{score_2}")
# Call your function with hard coded values
calculate_love_score("Kanye WesT", "Kim Kardashian")

15
parser_log.py Normal file
View file

@ -0,0 +1,15 @@
import collections
logs = [ "2026-05-26 ERROR: connection timeout", "2026-05-26 INFO: server started", "2026-05-26 ERROR: connection timeout", "2026-05-26 WARN: high memory", "2026-05-26 ERROR: disk full", ]
words = logs.split('#', 1)
error = collections.Counter('ERROR')
num_error = error.total()
print(f"Error: {num_error}")
# {'ERROR': 3, 'INFO': 1, 'WARN': 1} top erros: [('connection timeout', 2), ('disk full', 1)]