diff --git a/.idea/misc.xml b/.idea/misc.xml index a818314f..9d16f533 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ - + + + \ No newline at end of file diff --git a/SmartCalculator/Claculator.py b/SmartCalculator/Claculator.py new file mode 100644 index 00000000..0ed1992b --- /dev/null +++ b/SmartCalculator/Claculator.py @@ -0,0 +1,56 @@ +import random + +# Συνάρτηση που ζητάει από τον χρήστη να δώσει δύο αριθμούς (όρια) +def get_range(): + while True: + try: + lower_bound = float(input("Δώσε το κατώτερο όριο: ")) + upper_bound = float(input("Δώσε το ανώτερο όριο: ")) + if lower_bound > upper_bound: + print("Το κατώτερο όριο πρέπει να είναι μικρότερο ή ίσο με το ανώτερο όριο.") + else: + return lower_bound, upper_bound + except ValueError: + print("Παρακαλώ δώσε έγκυρους αριθμούς.") + +# Συνάρτηση που εκτελεί και εμφανίζει τις πράξεις +def calculate(num1, num2): + addition = num1 + num2 + subtraction = num1 - num2 + multiplication = num1 * num2 + + try: + division = num1 / num2 + except ZeroDivisionError: + division = None + + # Εμφάνιση των αποτελεσμάτων + print("\nΑποτελέσματα:") + print(f"Άθροισμα: {num1} + {num2} = {addition}") + print(f"Αφαίρεση: {num1} - {num2} = {subtraction}") + print(f"Πολλαπλασιασμός: {num1} * {num2} = {multiplication}") + + if division is not None: + print(f"Διαίρεση: {num1} / {num2} = {division}") + else: + print("Δεν είναι δυνατή η διαίρεση με το μηδέν.") + +# Κύρια συνάρτηση +def main(): + print("Πρόγραμμα αριθμητικών πράξεων") + + # Ζήτηση του διαστήματος από τον χρήστη + lower_bound, upper_bound = get_range() + + # Επιλογή τυχαίου αριθμού στο διάστημα που έδωσε ο χρήστης + random_num1 = random.uniform(lower_bound, upper_bound) + random_num2 = random.uniform(lower_bound, upper_bound) + + print(f"\nΤυχαίοι αριθμοί που επιλέχθηκαν: {random_num1} και {random_num2}") + + # Εκτέλεση των πράξεων + calculate(random_num1, random_num2) + +# Εκτέλεση του προγράμματος +if __name__ == "__main__": + main() diff --git a/SmartCalculator/README.md b/SmartCalculator/README.md new file mode 100644 index 00000000..d5665268 --- /dev/null +++ b/SmartCalculator/README.md @@ -0,0 +1,6 @@ +The user gives two numbers as limits (lower and upper). +The program asks for the lower and upper number, and makes sure that the lower limit is less than or equal to the upper limit. +The program selects two random numbers within the interval specified by the user. +The function random.uniform() selects random numbers between the lower and upper bounds. +Basic operations (addition, subtraction, multiplication, division) are performed. +If the random number chosen for the second number is 0, the division is not performed (to avoid an error). \ No newline at end of file