initial commit

This commit is contained in:
hoffmeisterda104361 committed 2026-10-19 20:29:13 +02:00
commit 39f56a3b10
83 files changed
+3583

No files matched your search

@@ -0,0 +1,6 @@
def calendar_check(i):
if i % 2 == 0:
print("Even")
else:
print("Odd")
+11
View File
@@ -0,0 +1,11 @@
import time
def countdown(lim):
i = lim
for x in range(lim+1):
print(i)
i = i-1
time.sleep(1)
countdown(10)
@@ -0,0 +1,4 @@
def fahrenheit_to_celsius(f):
c = (5.0 / 9.0) * (f - 32)
print(f"current temperature: {c:.1f}")
+20
View File
@@ -0,0 +1,20 @@
import random
def gamble():
counter = 0
print("in this game you have to guess a random number between 1 and 100")
target = int(random.randint(1,100))
while True:
guess = int(input("Take a guess! : "))
if target == guess:
print("You won!")
print("guesses taken: ",counter)
break
if target > guess:
print("too low")
if target < guess:
print("too high")
counter = counter+1
gamble()
+81
View File
@@ -0,0 +1,81 @@
def sequence_length():
sequence = input("Enter a sequence: ")
counter = 0
for sequence in sequence:
counter = counter+1
print("sequence length: ",counter)
def most_common_letter():
sequence = input("Enter a word: ")
letter = max(set(sequence), key=sequence.count)
print(f"The most common letter is '{letter}' and can be found {sequence.count(letter)} times")
def guarded_sum_loop():
print("Add numbers. Inputting '0' gives you the result")
result = 0
while True:
num = float(input("Enter a number: "))
if num == 0:
break
result = result + num
if result < 0:
print("NEGATIVE BALANCE")
break
print("Current balance: ", result)
def quadratic_calc():
MAX_NUM = 10
i = 0
result = 0
while i < MAX_NUM:
result = result + (i * i)
i = i + 1
print("quadratic sum between 0 and 10: ",result)
def time_passed():
sec = int(input("how many seconds passed? "))
min = sec // 60
sec = sec % 60
h = min // 60
min = min % 60
print(f"{h:02}:{min:02}:{sec:02}")
def list_sum():
numbers = [1,2,3,4,5,6,7]
result = 0
for x in numbers:
result = result + x
print(result)
def letter_counter():
text = input("Enter a text: ")
tar = input("Enter a letter: ")
i = 0
counter = 0
for text in text:
if text[i] == tar:
counter = counter + 1
print(f"This text contains the letter '{tar}' {counter} times")
def two_sum(lst, target):
o = len(lst)-1
counter = 0
for x in lst:
i = 0
while i < o:
checker = lst[i] + lst[o]
if target == checker:
print(f"combination found: {lst[i]} + {lst[o]} = {checker}")
#return lst[i], lst[o]
counter += 1
i = i + 1
o = o - 1
if counter == 0:
print("No combinations found")
#return None
two_sum([1,2,3,4,5,6,7,8,9,10,-1,-2],5)
+21
View File
@@ -0,0 +1,21 @@
def money_calc(money):
euros = money // 100
cents = money % 100
print(f"{euros}.{cents:02}")
def more_money(cents):
eur1 = cents // 100
cents = cents % 100
eur2 = eur1 // 1000
eur1 = eur1 % 1000
eur3 = eur2 // 1000
eur2 = eur2 % 1000
if eur3 > 0:
print(f'{eur3}.{eur2:03}.{eur1:03},{cents:02}')
elif eur2 > 0:
print( f'{eur2}.{eur1:03},{cents:02}')
else:
print(f'{eur1},{cents:02}')
more_money(3600780000)
+67
View File
@@ -0,0 +1,67 @@
import time
def m_narrator():
print("After days of drifting in darkness, you finally reach your destination - the moon")
time.sleep(5)
print(
"The onboard computer is about to finish the last few calculations to land you on the surface safely, as it suddenly stops")
print()
time.sleep(7)
print("ERROR: UNEXPECTED VARIABLES DETECTED")
time.sleep(2)
print("PROCEED WITH MANUAL LANDING")
print()
time.sleep(2)
print("Lucky that the sensors are still functioning")
time.sleep(2)
print("________________________")
print("ALTITUDE: 50.000m")
print("DESCENT SPEED: -1000m/s")
print("FUEL: 10.000l")
print("________________________")
time.sleep(2)
print("MOON ACCELERATION: -1,63m/s²")
print("ENGINE ACCELERATION: 12m/s²")
print("________________________")
time.sleep(3)
print()
print("As the gravity pulls you to your demise, the time to decide comes")
print()
def moon_landing():
#m_narrator()
fuel = 10000
altitude = 50000
speed = -1000
m_ac = -1.63
e_ac = 12
t = 1
while True:
if altitude <= 0:
if speed > -10:
print("You landed successfully")
else :
print("As your ship descended violently, you regretted not paying attention in physics class")
break
if input(f"Will you spend {100}l fuel to decelerate? (y/n): ") == "y":
print()
print("You turn the engines on for a while")
fuel = fuel - (100)
speed = speed+(e_ac*1)
altitude = altitude + speed
else :
print("you do nothing")
speed = speed+(m_ac*1)
altitude = altitude + speed
print("________________________")
print("ALTITUDE: ",altitude)
print("DESCENT SPEED: ",speed)
print("FUEL: ", fuel)
print("________________________")
print()
m_narrator()
moon_landing()
+131
View File
@@ -0,0 +1,131 @@
import random
ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"]
suits = ["of Clubs", "of Diamonds", "of Hearts", "of Spades"]
player_hand = []
dealer_hand = []
deck = []
class Player:
def draw(self):
card = random.choice(deck)
deck.remove(card)
player_hand.append(card)
return card
def hand_value(self):
total = 0
for _ in player_hand:
total += get_value(_)
return total
class Dealer:
def draw(self):
card = random.choice(deck)
deck.remove(card)
dealer_hand.append(card)
return card
def hand_value(self):
total = 0
for _ in dealer_hand:
total += get_value(_)
return total
def create_deck():
counter = 0
x = 0
for _ in range(len(suits)):
y = 0
for _ in range(len(ranks)):
deck.append(f"{ranks[y]} {suits[x]}")
y += 1
counter += 1
x += 1
return deck
def get_value(card):
if "2" in card:
return 2
if "3" in card:
return 3
if "4" in card:
return 4
if "5" in card:
return 5
if "6" in card:
return 6
if "7" in card:
return 7
if "8" in card:
return 8
if "9" in card:
return 9
if "10" in card:
return 10
if "Jack" in card or "Queen" in card or "King" in card:
return 10
if "Ace" in card:
return 11
return None
def main():
bank = 1000
while True:
global player
global dealer
player = Player()
dealer = Dealer()
create_deck()
p_stand = False
d_stand = False
for _ in range(2):
player.draw()
dealer.draw()
print(f"your current balance: {bank}")
bet = int(input("Enter your bet: "))
bank -= bet
while True:
print(f"Your hand: {player_hand} value: {player.hand_value()}")
print()
print(f"dealer card: {dealer_hand} value: {dealer.hand_value()}")
print()
if not p_stand:
if input("hit or stand (h/s): ") == "h":
print(f"you draw a card: {player.draw()}")
print()
else:
p_stand = True
if not d_stand:
if dealer.hand_value() < 17:
dealer.draw()
print(f"dealer draws a card: {dealer.draw()}")
print()
else:
d_stand = True
if player.hand_value() > 21:
print("you loose")
player_hand.clear()
dealer_hand.clear()
break
if player.hand_value() == 21:
print(f"you win ({bet * 2})")
bank = bank + bet * 2
player_hand.clear()
dealer_hand.clear()
deck.clear()
break
if bank == 0:
print("YOU HAVE NO MONEY")
break
if input("Do you want to play again? (y/n): ") == "n":
break
main()
+17
View File
@@ -0,0 +1,17 @@
import random
ranks = [2,3,4,5,6,7,8,9,10,"Jack","Queen","King","Ace"]
suits = ["of Clubs", "of Diamonds", "of Hearts", "of Spades"]
deck = []
counter = 0
y = 0
x = 0
for _ in range (len(suits)):
y = 0
for _ in range (len(ranks)):
deck.append(f"{ranks[y]} {suits[x]}")
y += 1
counter +=1
x +=1
print(deck[random.randint(0,len(deck)-1)])
+15
View File
@@ -0,0 +1,15 @@
class Student:
def __init__(self,name,s_id):
self.name = name
self.s_id = s_id
def __eq__(self,other):
if self.name == other.name and self.s_id == other.s_id:
return True
return False
s1=Student("A",1)
s2=Student("A",1)
if s1 == s2:
print("equal")
else:
print("not equal")
View File
Whitespace-only changes.
@@ -0,0 +1,41 @@
word = {}
def train():
with (open("vocab.txt", "r+")) as vocab:
for line in vocab:
word[line] = vocab.readline()
try:
while True:
if input(f"what is the translation of '{word[0]}'? ") in word[1]:
print("correct!")
break
else:
print("incorrect, try again")
except KeyError:
print("no such word in the library!")
print()
def save_vocab():
ger = input("enter a german word: ")
en = input("enter an english translation: ")
with (open("vocab.txt", "w")) as vocab:
vocab.write(f"{ger}, {en}")
while True:
print("1. Add a new word")
print("2. Train")
print("3. Quit")
user_inp = input()
if user_inp == "1":
save_vocab()
if user_inp == "2":
train()
if user_inp == "3":
break
+58
View File
@@ -0,0 +1,58 @@
class Animal:
def __init__(self,name,species,age):
self.name = name
self.species = species
self.age = age
def make_sound(self):
print()
class Bird(Animal):
def __str__(self):
return f"({self.species},{self.age})"
def make_sound(self):
print("chirp chirp")
class Mammal(Animal):
def __str__(self):
return f"({self.species},{self.age})"
def make_sound(self):
print("roar")
def main():
animals = {}
while True:
print("1. Add new mammal")
print("2. Add new bird")
print("3. List all animals")
print("4. Animal concert")
print("5. exit")
user_input = int(input("(1/2/3/4)?: "))
if user_input == 1:
age = input("Age: ")
species = input("Species: ")
name = input("Name: ")
animals[name] = str(Bird(name, species, age))
print()
if user_input == 2:
age = input("Age: ")
species = input("Species: ")
name = input("Name: ")
animals[name] = str(Mammal(name, species, age))
print()
if user_input == 3:
print(animals)
print()
if user_input == 4:
for animal_object in animals.values():
animal_object.make_sound()
if user_input == 5:
break
main()