-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnglishMeter.py
More file actions
84 lines (69 loc) · 1.96 KB
/
Copy pathEnglishMeter.py
File metadata and controls
84 lines (69 loc) · 1.96 KB
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
# Project 1
# Height to Meters
# Input:
# a) number from user (in feet) to convert to meters
# b) number in inches
# Output: converted values
#
# test input for all digits then convert to integer
# if length (number of characters) entered by user
# is zero, then the only entry is the return/enter key
# so quit
def CheckInput(inp):
# return key -> quit
if len(inp) == 0:
print("End program")
exit()
# check if - for negative number is in the string
if inp.find('-') == 0:
print("negative numbers not allowed")
exit()
# convert to a real number, if possible
try:
x = float(inp)
return x
except ValueError:
print("not a real number")
exit()
# user input routine
def GetUserFeet():
inFeet = input("Enter feet: ")
feet = CheckInput(inFeet)
return feet
def GetUserInches():
inInch = input("Enter inches: ")
inches = CheckInput(inInch)
if inches > 11:
print("that's bigger than a foot")
exit()
return inches
def CalculateTotalInches(ft, inh):
ti = ft * 12 + inh
return ti
def ConvertInchesToCentimeters(totalInches):
centimeters = totalInches * 2.54
return centimeters
def CalculateMeters(centimeters):
meters = centimeters / 10
return meters
def CheckError(e):
if e < 0:
print("error: ", e)
exit()
def DisplayAnswers(a,b,c,d,e):
print("--- answers ---")
print("Feet: ", a)
print("Inches: ", b)
print("CalculateTotalInches: ", c)
print("ConvertInchesToCentimeters: ", d)
print("CalculateMeters: ", e)
def main():
feet = GetUserFeet()
inches = GetUserInches()
totalInches = CalculateTotalInches(feet,inches)
centimeters = ConvertInchesToCentimeters(totalInches)
meters = CalculateMeters(centimeters)
DisplayAnswers(feet, inches, totalInches, centimeters, meters)
#if __name__ == "__main__":
# main()
main()