-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_calculator_app.py
88 lines (82 loc) · 3.32 KB
/
simple_calculator_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import secrets
print('Welcome to the calculator app!')
def addition(value, value_1):
print('This is addition')
result = value + value_1
return result
def subtraction(value, value_1):
print('This is subtraction')
result = value - value_1
return result
def multiplication(value, value_1):
print('This is multiplication')
result = value * value_1
return result
def division(value, value_1):
print('This is division')
result = value / value_1
return result
def power(value, value_1):
print('The value is a power')
result = value ** value_1
return result
while True:
ask_user = input('What you want to do?\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Power\n6.Random selection\n7.Exit\n')
if ask_user == '1':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = addition(number_1, number_2)
print(f'The result is {calculation}')
elif ask_user == '2':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = subtraction(number_1, number_2)
print(f'The result is {calculation}')
elif ask_user == '3':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = multiplication(number_1, number_2)
print(f'The result is {calculation}')
elif ask_user == '4':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = division(number_1, number_2)
print(f'The result is {calculation}')
elif ask_user == '5':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = power(number_1, number_2)
print(f'The result is {calculation}')
elif ask_user == '6':
computer_choice = secrets.choice(['1','2','3','4','5'])
print(f'Computer choice is, {computer_choice}')
if computer_choice == '1':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = addition(number_1, number_2)
print(f'The result is {calculation}')
elif computer_choice == '2':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = subtraction(number_1, number_2)
print(f'The result is {calculation}')
elif computer_choice == '3':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = multiplication(number_1, number_2)
print(f'The result is {calculation}')
elif computer_choice == '4':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = division(number_1, number_2)
print(f'The result is {calculation}')
elif computer_choice == '5':
number_1 = int(input('First number: '))
number_2 = int(input('Second number: '))
calculation = power(number_1, number_2)
print(f'The result is {calculation}')
elif ask_user == '7':
print('Exiting the calculator')
break
else:
print('This is not an option, try again!')