Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from enum import Enum
- class Options(Enum):
- ADDITION = 1
- SUBTRACTION = 2
- MULTIPLICATION = 3
- DIVISION = 4
- EXIT = 5
- def get_choice():
- return int(input("1. Zbrajanje\n2. Oduzimanje\n3. Množenje\n4. Dijeljenje\n5. Izlaz\n"))
- def invalid_choice(choice):
- return (choice < 1 or choice > 5)
- def get_array():
- numbers = [ ]
- for i in range(2):
- numbers.append(int(input("Unesite %i. broj: " % (i + 1))))
- return numbers
- def invalid_range_array(numbers):
- #has_out_of_range_number = False
- out_of_range = [ ]
- for i in numbers:
- if not(i >= 10 and i <= 100):
- out_of_range.append(i)
- has_out_of_range_number = len(out_of_range) > 0
- if has_out_of_range_number == True:
- for j in out_of_range:
- print("Broj %i nije u rasponu! (10, 100)" % (j))
- return has_out_of_range_number
- def get_valid_choice():
- choice = get_choice()
- while (invalid_choice(choice)):
- print("Nevažeći izbor! (%i)" % (choice))
- choice = get_choice()
- return choice
- def addition():
- numbers = get_array()
- if invalid_range_array(numbers) == True:
- return
- summed = sum(numbers)
- print("Zbroj brojeva %i i %i je %i" % (numbers[0], numbers[1], summed))
- def subtraction():
- numbers = get_array()
- if invalid_range_array(numbers) == True:
- return
- subtracted = numbers[0] - numbers[1]
- print("Razlika brojeva %i i %i je %i" % (numbers[0], numbers[1], subtracted))
- def multiplication():
- numbers = get_array()
- if invalid_range_array(numbers) == True:
- return
- multiplicitatated = numbers[0] * numbers[1]
- print("Umnožak brojeva %i i %i je %i" % (numbers[0], numbers[1], multiplicitatated))
- def division():
- numbers = get_array()
- if invalid_range_array(numbers) == True:
- return
- if numbers[0] == 0 or numbers[1] == 0:
- print("Unesena je nula!")
- return
- divisininated = numbers[0] / numbers[1]
- print("Količnik brojeva %i i %i je %i" % (numbers[0], numbers[1], divisininated))
- def select_operation(choice):
- if choice == Options.EXIT:
- print("cya")
- return
- if choice == Options.ADDITION:
- addition()
- elif choice == Options.SUBTRACTION:
- subtraction()
- elif choice == Options.MULTIPLICATION:
- multiplication()
- elif choice == Options.DIVISION:
- division()
- def main():
- choice = get_valid_choice()
- select_operation(choice)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement