-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtip.py
57 lines (41 loc) · 1.41 KB
/
tip.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
############################################
# #
# by : Ali Sharify #
# Dont copy currently Code #
# Github: alisharifyy #
# #
############################################
def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
d = d[1:]
d = float(d)
return d
def percent_to_float(p):
temp = p
location = temp.find("%")
temp = temp[:location]
temp = int(temp)
return (temp / 100)
main()
# -------------------------------------------------------------------------
# another way ===
# def main():
# dollars = dollars_to_float(input("How much was the meal? "))
# percent = percent_to_float(input("What percentage would you like to tip? "))
# tip = dollars * percent
# print(f"Leave ${tip:.2f}")
# def dollars_to_float(d):
# # replace $ with white space
# temp = d.replace("$","")
# temp = float(temp)
# return temp
# def percent_to_float(p):
# # in here we replace % with white space
# temp = p.replace("%","")
# # in here we divid temp to 100 to get us a decimal number like 15 ==> 0.15
# return (int(temp) / 100)
# main()