Home > Blockchain >  Why is my loop not ending in conversion program?
Why is my loop not ending in conversion program?

Time:01-08

I'm trying to write a Python program that converts degrees value from celsius to fahrenheit. For this, I followed a syntax previously used to create a calculator program, but the issue I'm encountering is receiving "(Pdb)" in the terminal after creating a while loop.

I tried ending the while loop with both 'break' and 'breakpoint'. Nothing really seems to be working.

#2. Write a Python program that converts degrees to and from celsius and fahrenheit
#This function converts degrees from celsius to fahrenheit
def conversiontype1(x):
  return x * 1.8   32
#This function converts degrees from fahrenheit to celsius

def conversiontype2(y):
  return y / 1.8 - 32

print("Select conversion type")
print("1.Celsius to Fahrenheit")
print("2.Fahrenheit to Celsius")

while True:
  #take input from the user
  choice = input("Enter choice 1/2: ")


  #check if choice is one of the two options
  #if choice in ('1','2'):

num1= float(input("Enter degrees"))
num2= float(input("Enter degrees"))

if choice == "1":
  print(num1, "*", 1.8, " ", 32)
elif choice == "2":
  print(num2, "/", 1.8, "-", 32)

#check if user wants another calculation

next_calculation = input("Let's do another calculation? (yes/no): ")
if next_calculation == 'no':
  print("Okay")
  breakpoint()

CodePudding user response:

you have a problem in the indentation In your code, assuming the indentation in the original code is correct, all you need to do is to change the breakpoint() to break, without the brackets. It worked on my machine

CodePudding user response:

#2. Write a Python program that converts degrees to and from celsius and fahrenheit
#This function converts degrees from celsius to fahrenheit
def conversiontype1(x):
  return x * 1.8   32
#This function converts degrees from fahrenheit to celsius

def conversiontype2(y):
  return y / 1.8 - 32

print("Select conversion type")
print("1.Celsius to Fahrenheit")
print("2.Fahrenheit to Celsius")

while True:
  #take input from the user
  choice = input("Enter choice 1/2: ")


  #check if choice is one of the two options
  #if choice in ('1','2'):

num1= float(input("Enter degrees"))
num2= float(input("Enter degrees"))

if choice == "1":
  print(num1, "*", 1.8, " ", 32)
elif choice == "2":
  print(num2, "/", 1.8, "-", 32)

#check if user wants another calculation

next_calculation = input("Let's do another calculation? (yes/no): ")
if next_calculation == 'no':
  print("Okay")
  breakpoint()
  • Related