-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmath_operator.py
94 lines (64 loc) · 1.9 KB
/
math_operator.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
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# coding: utf-8
# # Basic math operators
#
# - Math basic operators
# * + addition
# * - subtraction
# * * multiplication
# * / division
# In[1]:
# operators example
print("3 + 5 =",3 + 5)
print("3 + 5 - 9 =", 3 + 5 - 9)
print("48/9 =", 48/9)
print("5*5 =", 5*5)
print("(14 - 8)*(19/4) =", (14 - 8)*(19/4))
# In[6]:
# another example
def multiple():
make_big = input("Enter a non-decimal number you wish were bigger: ")
return int(make_big)*1000000
print("Now you have",multiple())
# In[9]:
# another example
print("15 - 43 : ",15 - 43)
print("15 * 43 : ",15 * 43)
print("156 / 12 : ",156 / 12)
print("21 / 0.5 : ",21 / 0.5)
print("( 111 + 84 ) - 45 : ",( 111 + 84 ) - 45)
print("(21 + 4 ) * 4 + 4 : ",( 21 + 4 ) * 4 + 4)
# In[16]:
# Multiplying Calculator Function
def multiply():
def user():
p1 = int(input("Enter first : "))
p2 = int(input("Enter second : "))
total = p1 * p2
return str(total)
return user()
z = multiply()
print("Multiply :",z)
# In[47]:
# Changed in Multiplying Calculator Function
def multiply(operator):
try:
p1 = float(input("Enter first : "))
p2 = float(input("Enter second : "))
if operator == "*":
return p1 * p2
elif operator == "/":
return p1 / p2
else:
return "Invalid Operator"
except Exception as e:
return("Enter correct input")
print(multiply(input("Enter '/' or '*' : ")))
# In[52]:
student_name = input("enter name: ").capitalize()
if student_name.startswith("F"):
print(student_name,"Congratulations, names starting with 'F' get to go first today!")
elif student_name.startswith("G"):
print(student_name,"Congratulations, names starting with 'G' get to go second today!")
else:
print(student_name, "please wait for students with names staring with 'F' and 'G' to go first today.")