d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > General Archive > Any Gcers Do Any Python Programming? > Lmk If U Can Help W/ This
12Next
Add Reply New Topic
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Jul 10 2015 11:23am
It is currently an infinite loop, i need it to end when the user enters "E", any help?



Code
choice = ""
def welcome():
print ("Welcome to the Metric Conversion Program\nThis program will take a unit of measurement and convert\nit to degrees Celcius or Meters.\n**********************************************************")

def choices(choice):
choice = ""
choice = str(input("Here are your choices:\n\tC for Celcius\n\tM for Meters\n\tE for Exit"))
Fahrenheit = 0.0
Celcius = 0.0
Feet = 0.0
Meters = 0.0
if choice == "C":
Celcius = fahrenheit_to_celcius(Fahrenheit,Celcius)
print (Celcius)
elif choice == "M":
Meters = feet_to_meters(Feet,Meters)
print (Meters)
elif choice == "E":
print("Thank you for using our program")
else:
print("Sorry you did not enter a C, M or E\nPlease try again: ")
choices(choice)
return choice

def fahrenheit_to_celcius(Fahrenheit,Celcius):
Fahrenheit = 0.0
Celcius = 0.0
Fahrenheit = float(input("Enter Degrees Fahrenheit: "))
Celcius = (5/9)*(Fahrenheit-32)
return Celcius

def feet_to_meters(Feet,Meters):
Feet = 0.0
Meters = 0.0
Feet = float(input("Enter Feet: "))
Meters = (0.305*Feet)
return Meters

def main():
choice = ""
Feet = 0.0
Meters = 0.0
Fahrenheit = 0.0
Celcius = 0.0
choice = choices(choice)
welcome()
while choice != "E":
main()


This post was edited by Drakwen on Jul 10 2015 11:39am
Member
Posts: 29,537
Joined: Apr 30 2006
Gold: 87.69
Jul 10 2015 11:41am
how much do u pay?
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Jul 10 2015 11:47am
Quote (normannen @ Jul 10 2015 12:41pm)
how much do u pay?


i know its something completely simple, ill figure it out if nothing else, let me know my small error and ill pay 20fg as a tip lol
Member
Posts: 29,537
Joined: Apr 30 2006
Gold: 87.69
Jul 10 2015 12:11pm
Quote (Drakwen @ 10 Jul 2015 19:47)
i know its something completely simple, ill figure it out if nothing else, let me know my small error and ill pay 20fg as a tip lol


elif choice == "E":
print("Thank you for using our program")
break

This post was edited by normannen on Jul 10 2015 12:13pm
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Jul 10 2015 12:18pm
Quote (normannen @ Jul 10 2015 01:11pm)
elif choice == "E":
print("Thank you for using our program")
break


this does not work to end the while loop, i cannot use an if loop because it only runs once if i use if choice != E: main()

for some reason choice is not translating to E at the end. because if choice == E right now, it should end the loop, which is what i dont understand

i had the choice designation in the wrong place thats all, it needed to be in the loop instead of in the main, this is how i fixed it.

Code
choice = ""
def welcome():
print ("Welcome to the Metric Conversion Program\nThis program will take a unit of measurement and convert\nit to degrees Celcius or Meters.\n**********************************************************")

def choices(choice):
choice = ""
choice = str(input("Here are your choices:\n\tC for Celcius\n\tM for Meters\n\tE for Exit"))
Fahrenheit = 0.0
Celcius = 0.0
Feet = 0.0
Meters = 0.0
if choice == "C":
Celcius = fahrenheit_to_celcius(Fahrenheit,Celcius)
print (Celcius)
elif choice == "M":
Meters = feet_to_meters(Feet,Meters)
print (Meters)
elif choice == "E":
print("Thank you for using our program")
else:
print("Sorry you did not enter a C, M or E\nPlease try again: ")
choices(choice)
return choice

def fahrenheit_to_celcius(Fahrenheit,Celcius):
Fahrenheit = 0.0
Celcius = 0.0
Fahrenheit = float(input("Enter Degrees Fahrenheit: "))
Celcius = (5/9)*(Fahrenheit-32)
return Celcius

def feet_to_meters(Feet,Meters):
Feet = 0.0
Meters = 0.0
Feet = float(input("Enter Feet: "))
Meters = (0.305*Feet)
return Meters

def main():
choice = ""
Feet = 0.0
Meters = 0.0
Fahrenheit = 0.0
Celcius = 0.0

welcome()
while choice != "E":
main()
choice = choices(choice)


This post was edited by Drakwen on Jul 10 2015 12:25pm
Member
Posts: 29,537
Joined: Apr 30 2006
Gold: 87.69
Jul 10 2015 12:26pm
Quote (Drakwen @ 10 Jul 2015 20:18)
this does not work to end the while loop, i cannot use an if loop because it only runs once if i use if choice != E: main()

for some reason choice is not translating to E at the end. because if choice == E right now, it should end the loop, which is what i dont understand


are you practising something special here or do u just want a converter?

example with tkinter
https://github.com/EssenceOfZen/Python-Temperature-Converter/blob/master/Temperature%20Conversion.py

This post was edited by normannen on Jul 10 2015 12:28pm
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Jul 10 2015 12:33pm
Quote (normannen @ Jul 10 2015 01:26pm)
are you practising something special here or do u just want a converter?

example with tkinter
https://github.com/EssenceOfZen/Python-Temperature-Converter/blob/master/Temperature%20Conversion.py


it was an assignment i had for a college class... meant to practice using functions and call statements instead of writing everything hard coded. its done lol

This post was edited by Drakwen on Jul 10 2015 12:34pm
Member
Posts: 155,743
Joined: Mar 28 2008
Gold: 224.50
Jul 10 2015 12:33pm
yas eye does
Member
Posts: 29,537
Joined: Apr 30 2006
Gold: 87.69
Jul 10 2015 12:39pm
Quote (Drakwen @ 10 Jul 2015 20:33)
it was an assignment i had for a college class... meant to practice using functions and call statements instead of writing everything hard coded. its done lol


ah i see. i'm also learning python^^

what books are you guys following?

This post was edited by normannen on Jul 10 2015 12:40pm
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Jul 10 2015 12:42pm
Quote (normannen @ Jul 10 2015 01:39pm)
ah i see. i'm also learning python^^


gotcha, i ended up getting rid of the main function all together, ended up looking like this to turn in, and just so u know i am forced to comment the obvious i dont do it because im retarded lol she will lower the grade if i dont.

Code
choice = "" #Variable Declaration
def welcome(): #Welcome function
print ("Welcome to the Metric Conversion Program\nThis program will take a unit of measurement and convert\nit to degrees Celcius or Meters.\n**********************************************************") #Welcome print statement

def choices(choice): #choices function
choice = "" #Variable declaration
choice = str(input("Here are your choices:\n\tC for Celcius\n\tM for Meters\n\tE for Exit")) #Choices input
Fahrenheit = 0.0 #Variable declaration
Celcius = 0.0 #Variable declaration
Feet = 0.0 #Variable declaration
Meters = 0.0 #Variable declaration
if choice == "C": #If statement for choice
Celcius = fahrenheit_to_celcius(Fahrenheit,Celcius) #Celcius declaration as fahrenheit function
print (Celcius) #print statement for celcius
elif choice == "M": #elif statement for choice
Meters = feet_to_meters(Feet,Meters) #Meters declaration as feet to meters function
print (Meters) #Meters print statement
elif choice == "E": #elif statement for choice
print("Thank you for using our program") #Thank you for using print statement
else:
print("Sorry you did not enter a C, M or E\nPlease try again: ") #Wrong info print statement
choices(choice) #run choices function again if wrong info is put in
return choice #return choice variable

def fahrenheit_to_celcius(Fahrenheit,Celcius): #fahrenheit to celcius function
Fahrenheit = 0.0 #Variable declaration
Celcius = 0.0 #Variable declaration
Fahrenheit = float(input("Enter Degrees Fahrenheit: ")) #Fahrenheit input
Celcius = (5/9)*(Fahrenheit-32) #Fahrenheit to celcius formula
return Celcius #return celcius variable

def feet_to_meters(Feet,Meters): #Feet to meters function
Feet = 0.0 #Variable declaration
Meters = 0.0 #Variable declaration
Feet = float(input("Enter Feet: ")) #Feet input
Meters = (0.305*Feet) #feet to meters formula
return Meters #Meters Return

welcome() #Welcome function call statement
while choice != "E": #While loop for program
choice = choices(choice) #Runs choices function
Go Back To General Archive Topic List
12Next
Add Reply New Topic