Skip to content

-m "alexkafa| SmartCalculator | Changes" #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions SmartCalculator/Claculator.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions SmartCalculator/README.md
Original file line number Diff line number Diff line change
@@ -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).