repl.it
@PyShare/

Calculator

Python

Tidy version of @UZ's calculator.

fork
loading
Files
  • main.py
main.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
83
84
import time #imports the time to create a wait
P = 0.8 #defines how long P will be in a time.sleep
for i in range(101):
  print('Loading:', i)
  #prints a 'loading screen' mechanism
print('Success!')
time.sleep(P) #creates an actual wait in the code
print('Success!')
time.sleep(P)
print('Success!')
print(' ')
time.sleep(P)
print('Welcome to UZs Calculator! (Code was tidied by PyShare)') 
print(' ')
time.sleep(P)
#prints a blank space to create a wait
name = input('Enter a nickname.\n')
#provides a one-time nickname to use, is completely unnecessary
print(' ')
time.sleep(P)
print('Welcome, %s.' % name)
print(' ')
time.sleep(P)
code = input('Create a code.\n')
print(' ')

#creates a code to associate with the nickname given
time.sleep(P)
print('Created code %s.' % code)
print(' ')
time.sleep(P)
print('Your name, %s' %name)
print('has been associated with code %s' % code)
#this line tells the user that their nickname is associated with their code
time.sleep(P)
print('Opening calculator:')

for i in range(5001):
  print('Loading:', i)
time.sleep(P)
print(' ')

print('Success!')
time.sleep(P)
print(' ')
#-->BEGINNING OF THE CODE FOR THE CALCULATOR<--#
def add(num1, num2):
    return num1 + num2

def subtract(num1, num2):
    return num1 - num2

def div(num1, num2):
    return num1/num2

def multi(num1,num2):
    return num1*num2

def main():
    operation = input("What is the operation you wish to use for the calculation?(+, -, *, or /):")
    if (operation != "+" and operation != "-" and operation != "*" and operation != "/"):
        print("Your input is invalid. Please enter a valid input from the ones listed above.")
        #allows the user to choose from the operations listed, and returns an invalid input print if the input is not listed above
    else:
        num1 = float(input("Enter your first number: "))
        num2 = float(input("Enter your second number: "))
        #asks for a number value for inputs
        if (operation == "+"):
            print(add(num1, num2))
        elif (operation == "-"):
            print(subtract(num1, num2))
        elif (operation == "*"):
            print(multi(num1,num2))
        elif (operation == "/"):
            print(div(num1,num2))
            #prints the value outputted from the calculation inputted

main()
print('Thank you for using UZs calculator.')
feedback = input('Did you enjoy using the calculator?\n')
if input == "Yes":
  then: print('Thank you')
else: print('Thank you for using the calculator')
print('Thank you to PyShare for cleaning the code')
Fetching token
?