aboutsummaryrefslogtreecommitdiff
path: root/Python/Beginner training
diff options
context:
space:
mode:
Diffstat (limited to 'Python/Beginner training')
-rw-r--r--Python/Beginner training/001 GoSkiing.py12
-rw-r--r--Python/Beginner training/002 Pets.py18
-rw-r--r--Python/Beginner training/003 Hotel.py31
-rw-r--r--Python/Beginner training/004 TakingCare.py15
-rw-r--r--Python/Beginner training/011 FitnessEquipment.py16
-rw-r--r--Python/Beginner training/012 FitnessVisitors.py25
-rw-r--r--Python/Beginner training/Classes.py238
-rw-r--r--Python/Beginner training/Exam 1.py78
-rw-r--r--Python/Beginner training/Exam 2.py48
-rw-r--r--Python/Beginner training/Random.py67
-rw-r--r--Python/Beginner training/Tasks.py71
11 files changed, 435 insertions, 184 deletions
diff --git a/Python/Beginner training/001 GoSkiing.py b/Python/Beginner training/001 GoSkiing.py
deleted file mode 100644
index 28f6f33..0000000
--- a/Python/Beginner training/001 GoSkiing.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import sys
-import os
-
-skier_n = int(input('Type number of skiers: '))
-jacket_n_per_person = int(input('Type number of jackets per person: '))
-helmet_n_per_person = int(input('Type number of helmets per person: '))
-shoe_set_n_per_person = int(input('Type number of shoes per person: '))
-
-total_per_person = (jacket_n_per_person * 120) + (helmet_n_per_person * 75) + (shoe_set_n_per_person * 299.9)
-total_price = total_per_person * skier_n
-
-print('Total price for all skiers: ', round(total_price + total_price * 0.2, 2)) \ No newline at end of file
diff --git a/Python/Beginner training/002 Pets.py b/Python/Beginner training/002 Pets.py
deleted file mode 100644
index bdc5a3b..0000000
--- a/Python/Beginner training/002 Pets.py
+++ /dev/null
@@ -1,18 +0,0 @@
-import sys
-import os
-import math
-
-days_absent = int(input('Type the number of days that you wil be absent: '))
-left_food_kg = float(input('Type the number of left food in kg: '))
-daily_consumption_first = float(input('Type the daily consumption of the first cat in kg: '))
-daily_consumption_second = float(input('Type the daily consumption of the second cat in kg: '))
-
-left_food_kg -= days_absent * daily_consumption_first
-left_food_kg -= days_absent * daily_consumption_second
-
-if left_food_kg >= 0:
- print('The cats are well fed')
- print('{} kilos of food left'.format(left_food_kg))
-else:
- print('The cats are hungry')
- print('{} more kilos of food are needed'.format(int(abs(left_food_kg)))) \ No newline at end of file
diff --git a/Python/Beginner training/003 Hotel.py b/Python/Beginner training/003 Hotel.py
deleted file mode 100644
index 0e2ed2a..0000000
--- a/Python/Beginner training/003 Hotel.py
+++ /dev/null
@@ -1,31 +0,0 @@
-import sys
-import os
-import math
-
-n_nights = int(input('Type number of nights: '))
-room_type = input('Type the type of room: ')
-
-price = 0.0
-if room_type == 'apartment':
- price = n_nights * 70
-else:
- price = n_nights * 125
-
-#code doesn't account for writing mistakes
-if n_nights < 10:
- if room_type == 'apartment':
- price *= 0.7
- else:
- price *= 0.9
-elif n_nights > 15:
- if room_type == 'apartment':
- price *= 0.5
- else:
- price *= 0.8
-else:
- if room_type == 'apartment':
- price *= 0.65
- else:
- price *= 0.85
-
-print('Total price: {}'.format(round(price, 2))) \ No newline at end of file
diff --git a/Python/Beginner training/004 TakingCare.py b/Python/Beginner training/004 TakingCare.py
deleted file mode 100644
index 47143a3..0000000
--- a/Python/Beginner training/004 TakingCare.py
+++ /dev/null
@@ -1,15 +0,0 @@
-import sys
-import os
-import math
-
-food = int(input('Type bought amount of food in kg: ')) * 1000
-days_care = int(input('Type days the the animals wil be taken care of: '))
-
-for i in range(days_care):
- daily_consumption = int(input('Food that the animal has eaten that day: '))
- food -= daily_consumption
-
-if food >= 0:
- print('Food is enough! Leftovers: {} grams'.format(food))
-else:
- print('Food is not enough. You need {} grams more'.format(abs(food))) \ No newline at end of file
diff --git a/Python/Beginner training/011 FitnessEquipment.py b/Python/Beginner training/011 FitnessEquipment.py
deleted file mode 100644
index a8046da..0000000
--- a/Python/Beginner training/011 FitnessEquipment.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import sys
-import math
-import random
-import os
-
-total_sum = 0.0
-for x in range(int(input())):
- item_name = input()
-
- if item_name == "treadmill": total_sum += 5899
- elif item_name == "cross trainer": total_sum += 1699
- elif item_name == "exercise bike": total_sum += 1789
- elif item_name == "dumbells": total_sum += 579
- else: print("ERROR, Invalid product name")
-
-print(round(total_sum, 2)) \ No newline at end of file
diff --git a/Python/Beginner training/012 FitnessVisitors.py b/Python/Beginner training/012 FitnessVisitors.py
deleted file mode 100644
index 382c145..0000000
--- a/Python/Beginner training/012 FitnessVisitors.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import sys
-import math
-import random
-import os
-
-names = list(input("Type names: ").split(", "))
-
-while True:
- command = input()
- if command == "END": break
-
- if command == "Add visitor":
- names.append(input())
- elif command == "Add visitor on position":
- name_to_insert = input()
- names.insert(int(input()), name_to_insert)
- elif command == "Remove visitor on position":
- names.pop(int(input()))
- elif command == "Remove last visitor":
- names.pop(len(names) - 1)
- elif command == "Remove first visitor":
- names.pop(0)
- else: print("ERROR, indxistant command")
-
-print(names)
diff --git a/Python/Beginner training/Classes.py b/Python/Beginner training/Classes.py
new file mode 100644
index 0000000..ea537f8
--- /dev/null
+++ b/Python/Beginner training/Classes.py
@@ -0,0 +1,238 @@
+import sys
+import math
+import random
+import os
+
+def BankAccountTask():
+ class BankAccount:
+ def __init__(self, id, balance):
+ self.id = int(id)
+ self.__balance = float(balance)
+
+ def Deposit(self, amount):
+ self.__balance += amount
+
+ def Withdraw(self, amount):
+ self.__balance -= amount
+
+ def GetBalance(self):
+ return self.__balance
+
+ def __str__(self):
+ return "Account {0}, balance {1}".format(self.id, self.GetBalance())
+
+ accounts = {}
+ while True:
+ command = input().split(' ')
+
+ if command[0].lower() == "end":
+ break
+ elif command[0] == "Add":
+ accounts[int(command[1])] = BankAccount(int(command[1]), float(command[2]))
+ elif command[0] == "Deposit":
+ accounts[int(command[1])].Deposit(float(command[2]))
+ elif command[0] == "Withdraw":
+ accounts[int(command[1])].Withdraw(float(command[2]))
+ elif command[0] == "Info":
+ print(accounts[int(command[1])])
+ elif command[0] == "Print":
+ for acc in accounts: print(accounts[acc])
+ else:
+ print("Invalid command!")
+
+
+def PizzaTask():
+ class Dough():
+ def __init__(self, type, cooking_method, weight):
+ type = type.lower(); cooking_method = cooking_method.lower()
+ self.__validate(type, cooking_method, weight)
+
+ self.__type = str(type)
+ self.__cooking_method = str(cooking_method)
+ self.__weight = int(weight)
+
+ self.__total_cals = 2.0 * self.__weight
+ if type == "white": self.__total_cals *= 1.5
+ if cooking_method == "crispy":
+ self.__total_cals *= 0.9
+ elif cooking_method == "chewy":
+ self.__total_cals *= 1.1
+
+ def __validate(self, type, cooking_method, weight):
+ type = str(type); cooking_method = str(cooking_method); weight = int(weight)
+
+ if (type != "white" and type != "wholegrain") or \
+ (cooking_method != "crispy" and cooking_method != "chewy" and cooking_method != "homemade"):
+ raise ValueError()
+
+ if weight < 1 or weight > 200:
+ raise NameError()
+
+ def get_cals(self):
+ return self.__total_cals
+
+ class Topping():
+ def __init__(self, type, weight):
+ type = type.lower()
+ self.__validate(type, weight)
+
+ self.__type = str(type)
+ self.__weight = int(weight)
+
+ self.__total_cals = 2.0 * self.__weight
+ if type == "veggies":
+ self.__total_cals *= 0.8
+ elif type == "sauce":
+ self.__total_cals *= 0.9
+ elif type == "cheese":
+ self.__total_cals *= 1.1
+ else:
+ self.__total_cals *= 1.2 # Sauce
+
+ def __validate(self, type, weight):
+ type = str(type); weight = int(weight)
+
+ # usng different types of error to indicate what to write on screen
+ if type != "meat" and type != "veggies" and type != "cheese" and type != "sauce":
+ raise AssertionError()
+
+ if weight < 1 or weight > 50:
+ raise AttributeError()
+
+ def get_cals(self):
+ return self.__total_cals
+
+ class Pizza():
+ def __init__(self, name, num):
+ self.__validate(name, num)
+
+ self.name = str(name)
+ self.__dough = None # not public because task doesn't want it to be
+ self.__toppings = []
+ self.__total_cals = 0.0
+
+ def __validate(self, name, num):
+ name = str(name); num = int(num)
+
+ if len(name) < 1 or len(name) > 15:
+ raise MemoryError()
+
+ if num < 0 or num > 10:
+ raise IndexError()
+
+ def add_dough(self, dough):
+ self.__dough = dough
+ self.__total_cals += dough.get_cals()
+
+ def add_topping(self, topping):
+ self.__toppings.append(topping)
+ self.__total_cals += topping.get_cals()
+
+ def __str__(self):
+ return "{0} - {1} Calories.".format(self.name, self.__total_cals)
+
+ def n_toppings(self):
+ return len(self.__toppings)
+
+ def cals(self):
+ return self.__total_cals
+
+ info = input().split(' ')
+ try:
+ in_pizza = Pizza(info[1], info[2])
+
+ info = input().split(' ')
+ in_pizza.add_dough(Dough(info[1], info[2], info[3]))
+
+ while True:
+ info = input().split(' ')
+
+ if info[0].lower() == "end":
+ break
+ else:
+ in_pizza.add_topping(Topping(info[1], info[2]))
+
+ print(in_pizza)
+
+ except ValueError:
+ print('Invalid type of dough.')
+ except NameError:
+ print('Dough weight should be in the range [1..200].')
+ except AssertionError:
+ print('Cannot place {0} on top of your pizza.'.format(info[1]))
+ except AttributeError:
+ print('{0} weight should be in the range [1..50].'.format(info[1]))
+ except MemoryError:
+ print('Pizza name should be between 1 and 15 symbols.')
+ except IndexError:
+ print('Number of toppings should be in range [0..10].')
+
+ while True:
+ command = input().split(' ')
+
+ if command[0] == "END": break
+ # elif command[0] == "Dough":
+
+
+def CarVender():
+ class Engine():
+ def __init__(self, model, power, displacement = 'n/a', efficiency = 'n/a'):
+ self.__model = model
+ self.__power = power
+ self.displacement = displacement
+ self.efficiency = efficiency
+
+ def __str__(self):
+ return " {0}:\n Power: {1}\n Displacement: {2}\n Efficiency: {3}"\
+ .format(self.__model, self.__power, self.displacement, self.efficiency)
+
+ class Car():
+ def __init__(self, model, engine, weight = 'n/a', color = 'n/a'):
+ self.__model = model
+ self.__engine = engine
+ self.weight = weight
+ self.color = color
+
+ def __str__(self):
+ return "{0}:\n{1}\n Weight: {2}\n Color: {3}"\
+ .format(self.__model, self.__engine, self.weight, self.color)
+
+ engines = {}
+ engines_n = int(input())
+ for i in range(engines_n):
+ info = input().split(' ')
+ list(filter(lambda e: e != ' ', info))
+
+ engines[info[0]] = (Engine(info[0], info[1]))
+ if len(info) == 3:
+ try:
+ engines[info[0]].displacement = int(info[2])
+ except:
+ engines[info[0]].efficiency = info[2]
+ elif len(info) == 4:
+ engines[info[0]].displacement = int(info[2])
+ engines[info[0]].efficiency = info[3]
+
+ cars = []
+ cars_n = int(input())
+ for i in range(cars_n):
+ info = input().split(' ')
+ info = [e for e in info if e != '']
+
+ cars.append(Car(info[0], engines[info[1]]))
+ if len(info) == 3:
+ try:
+ cars[i].weight = int(info[2])
+ except:
+ cars[i].color = info[2]
+ elif len(info) == 4:
+ cars[i].weight = info[2]
+ cars[i].color = info[3]
+
+ for curr_car in cars:
+ print(curr_car)
+
+
+#BankAccountTask()
+#PizzaTask()
+CarVender()
diff --git a/Python/Beginner training/Exam 1.py b/Python/Beginner training/Exam 1.py
new file mode 100644
index 0000000..6e04541
--- /dev/null
+++ b/Python/Beginner training/Exam 1.py
@@ -0,0 +1,78 @@
+import sys
+import math
+import random
+import os
+
+def GoSkiing():
+ skier_n = int(input('Type number of skiers: '))
+ jacket_n_per_person = int(input('Type number of jackets per person: '))
+ helmet_n_per_person = int(input('Type number of helmets per person: '))
+ shoe_set_n_per_person = int(input('Type number of shoes per person: '))
+
+ total_per_person = (jacket_n_per_person * 120) + (helmet_n_per_person * 75) + (shoe_set_n_per_person * 299.9)
+ total_price = total_per_person * skier_n
+
+ print('Total price for all skiers: ', round(total_price + total_price * 0.2, 2))
+
+def Pets():
+ days_absent = int(input('Type the number of days that you wil be absent: '))
+ left_food_kg = float(input('Type the number of left food in kg: '))
+ daily_consumption_first = float(input('Type the daily consumption of the first cat in kg: '))
+ daily_consumption_second = float(input('Type the daily consumption of the second cat in kg: '))
+
+ left_food_kg -= days_absent * daily_consumption_first
+ left_food_kg -= days_absent * daily_consumption_second
+
+ if left_food_kg >= 0:
+ print('The cats are well fed')
+ print('{} kilos of food left'.format(left_food_kg))
+ else:
+ print('The cats are hungry')
+ print('{} more kilos of food are needed'.format(int(abs(left_food_kg))))
+
+def Hotel():
+ n_nights = int(input('Type number of nights: '))
+ room_type = input('Type the type of room: ')
+
+ price = 0.0
+ if room_type == 'apartment':
+ price = n_nights * 70
+ else:
+ price = n_nights * 125
+
+ # code doesn't account for writing mistakes
+ if n_nights < 10:
+ if room_type == 'apartment':
+ price *= 0.7
+ else:
+ price *= 0.9
+ elif n_nights > 15:
+ if room_type == 'apartment':
+ price *= 0.5
+ else:
+ price *= 0.8
+ else:
+ if room_type == 'apartment':
+ price *= 0.65
+ else:
+ price *= 0.85
+
+ print('Total price: {}'.format(round(price, 2)))
+
+def TakingCare():
+ food = int(input('Type bought amount of food in kg: ')) * 1000
+ days_care = int(input('Type days the the animals wil be taken care of: '))
+
+ for i in range(days_care):
+ daily_consumption = int(input('Food that the animal has eaten that day: '))
+ food -= daily_consumption
+
+ if food >= 0:
+ print('Food is enough! Leftovers: {} grams'.format(food))
+ else:
+ print('Food is not enough. You need {} grams more'.format(abs(food)))
+
+GoSkiing()
+Pets()
+Hotel()
+TakingCare() \ No newline at end of file
diff --git a/Python/Beginner training/Exam 2.py b/Python/Beginner training/Exam 2.py
new file mode 100644
index 0000000..c3d20bd
--- /dev/null
+++ b/Python/Beginner training/Exam 2.py
@@ -0,0 +1,48 @@
+import sys
+import math
+import random
+import os
+
+def FitnessEquipment():
+ total_sum = 0.0
+ for x in range(int(input())):
+ item_name = input()
+
+ if item_name == "treadmill":
+ total_sum += 5899
+ elif item_name == "cross trainer":
+ total_sum += 1699
+ elif item_name == "exercise bike":
+ total_sum += 1789
+ elif item_name == "dumbells":
+ total_sum += 579
+ else:
+ print("ERROR, Invalid product name")
+
+ print(round(total_sum, 2))
+
+def FitnessVisitors():
+ names = list(input("Type names: ").split(", "))
+
+ while True:
+ command = input()
+ if command == "END": break
+
+ if command == "Add visitor":
+ names.append(input())
+ elif command == "Add visitor on position":
+ name_to_insert = input()
+ names.insert(int(input()), name_to_insert)
+ elif command == "Remove visitor on position":
+ names.pop(int(input()))
+ elif command == "Remove last visitor":
+ names.pop(len(names) - 1)
+ elif command == "Remove first visitor":
+ names.pop(0)
+ else:
+ print("ERROR, indxistant command")
+
+ print(names)
+
+FitnessEquipment()
+FitnessVisitors() \ No newline at end of file
diff --git a/Python/Beginner training/Random.py b/Python/Beginner training/Random.py
deleted file mode 100644
index d913a72..0000000
--- a/Python/Beginner training/Random.py
+++ /dev/null
@@ -1,67 +0,0 @@
-import sys
-import os
-import random
-import math
-
-
-
-''' Divide
-cycle_n = int(input("Type number of numbers that will be typed: "))
-p1 = 0; p2 = 0; p3 = 0
-
-for x in range(cycle_n):
- num = int(input())
-
- if num % 2 == 0: p1 += 1
- if num % 3 == 0: p2 += 1
- if num % 4 == 0: p3 += 1
-
-print(round(p1 * 100 / cycle_n, 2), "%")
-print(round(p2 * 100 / cycle_n, 2), "%")
-print(round(p3 * 100 / cycle_n, 2), "%")
-
-'''
-
-''' Histogram
-cycle_n = int(input("Type number of numbers that will be typed: "))
-p1 = 0; p2 = 0; p3 = 0; p4 = 0; p5 = 0
-
-for x in range(cycle_n):
- num = int(input())
-
- if num < 200: p1 += 1
- elif num < 400: p2 += 1
- elif num < 600: p3 += 1
- elif num < 800: p4 += 1
- else: p5 += 1
-
-print(round(p1 * 100 / cycle_n, 2), "%")
-print(round(p2 * 100 / cycle_n, 2), "%")
-print(round(p3 * 100 / cycle_n, 2), "%")
-print(round(p4 * 100 / cycle_n, 2), "%")
-print(round(p5 * 100 / cycle_n, 2), "%")
-'''
-
-''' Number matrix
-size = int(input("Type size of matrix: "))
-
-for x in range(size):
- for y in range(size):
- num = y + x + 1
-
- if num <= size or x == 0:
- print(end="{} ".format(num)) #doing it like this for practice
- else:
- print(end="{} ".format(2 * size - num)) #doing it like this for practice
- else: print()
-'''
-
-''' Factoriel code:
-factoriel_n = int(input("Type times of factoriel: "))
-
-final_int = 1
-for x in range(1, factoriel_n + 1):
- final_int *= x
-
-print(final_int)
-''' \ No newline at end of file
diff --git a/Python/Beginner training/Tasks.py b/Python/Beginner training/Tasks.py
new file mode 100644
index 0000000..873bde6
--- /dev/null
+++ b/Python/Beginner training/Tasks.py
@@ -0,0 +1,71 @@
+import sys
+import os
+import random
+import math
+
+def Divide():
+ cycle_n = int(input("Type number of numbers that will be typed: "))
+ p1 = 0; p2 = 0; p3 = 0
+
+ for x in range(cycle_n):
+ num = int(input())
+
+ if num % 2 == 0: p1 += 1
+ if num % 3 == 0: p2 += 1
+ if num % 4 == 0: p3 += 1
+
+ print(round(p1 * 100 / cycle_n, 2), "%")
+ print(round(p2 * 100 / cycle_n, 2), "%")
+ print(round(p3 * 100 / cycle_n, 2), "%")
+
+def Histogram():
+ cycle_n = int(input("Type number of numbers that will be typed: "))
+ p1 = 0; p2 = 0; p3 = 0; p4 = 0; p5 = 0
+
+ for x in range(cycle_n):
+ num = int(input())
+
+ if num < 200:
+ p1 += 1
+ elif num < 400:
+ p2 += 1
+ elif num < 600:
+ p3 += 1
+ elif num < 800:
+ p4 += 1
+ else:
+ p5 += 1
+
+ print(round(p1 * 100 / cycle_n, 2), "%")
+ print(round(p2 * 100 / cycle_n, 2), "%")
+ print(round(p3 * 100 / cycle_n, 2), "%")
+ print(round(p4 * 100 / cycle_n, 2), "%")
+ print(round(p5 * 100 / cycle_n, 2), "%")
+
+def NumberMatrix():
+ size = int(input("Type size of matrix: "))
+
+ for x in range(size):
+ for y in range(size):
+ num = y + x + 1
+
+ if num <= size or x == 0:
+ print(end="{} ".format(num)) # doing it like this for practice
+ else:
+ print(end="{} ".format(2 * size - num)) # doing it like this for practice
+ else:
+ print()
+
+def Factoriel():
+ factoriel_n = int(input("Type times of factoriel: "))
+
+ final_int = 1
+ for x in range(1, factoriel_n + 1):
+ final_int *= x
+
+ print(final_int)
+
+Divide()
+Histogram()
+NumberMatrix()
+Factoriel() \ No newline at end of file