I'm very very fresh to programming. This is one of my first experiments with Python and I'm wondering in what ways I could have made this program less clunky. Specifically, is there a way that I could have used classes instead of defining my x, y, and z variables globally?
def getx():
try:
global x
x = float(raw_input("Please give your weight (pounds): "))
return x
except ValueError:
print("Use a number, silly!")
getx()
def gety():
try:
global y
y = float(raw_input("what is your current body fat percentage? (>1): "))
return y
except ValueError:
print("Use a number, silly!")
gety()
def getz():
try:
global z
z = float(raw_input("What is your desired body fat percentage? (>1): "))
return z
except ValueError:
print("Use a number, silly!")
getz()
def output():
getx()
gety()
getz()
A = (x*(y/100-z/100))/(1-z/100)
B = x - A
print("Your necessary weight loss is %.1f pounds, and \
your final weight will be %.1f pounds" % (A,B))
more()
def more():
again = raw_input("Calculate again? ")
if again.lower() == "yes" or \
again.lower() == "y" or \
again.lower() == "sure" or \
again.lower() == "ok" or \
again.lower() == "" or \
again.lower() == "okay":
output()
elif again.lower() == "no" or \
again.lower() == "n" or \
again.lower() == "nah" or \
again.lower() == "nope":
end()
else:
more()
def end():
print("Ok, see ya later!")
output()