Create a program that allows the user to convert a range of values from feet to centimeter or centimeter to feet

Question:

I’m having a hard time including the conversion rates and the range. Can you help me with this? I’m a beginner programming in Python. Thank you so much. (https://i.stack.imgur.com/0PW99.jpg)]

Sample of expected output:

This program will convert a range of LENGTH 
Enter (F) to convert Feet to Centimeter 
Enter (C to convert Centimeter to Feet 

Enter Selection: F 
Enter starting length to convert: 10 
Enter ending length to convert: 20 

 Length Length 
Feet Centimeter 
  10.0 304.8
  11.0 335.3 
  12.0 365.8 
  13.0 396.2 
  14.0 426.7 
  15.0 457.2 
  16.0 487.7 
  17.0 518.2 
  18.0 548.6 
  19.0 579.1 
  20.0 609.6

Here’s my initial input, but I really can’t manage to do it. enter image description here

print("This program will convert a range of LENGTH ")
print("Enter (F) to convert Feet to Centimeter")
print("Enter (C) to convert Centimeter to Feet")
print()
feet = 'F'
centimeter = 'C'
which = input("Enter Selection: ",  )
meas_start = int(input("Enter starting length to convert: "))
meas_end = int(input("Enter ending length to convert: "))
print()
print(" Length Length")
print("Feet Centimeter")
if meas_start == feet:

Answers:

Try this code

print("This program will convert a range of LENGTH ")
print("Enter (F) to convert Feet to Centimeter")
print("Enter (C) to convert Centimeter to Feet")
print()
feet = 'F'
centimeter = 'C'
which = input("Enter Selection: ",  )
meas_start = int(input("Enter starting length to convert: "))
meas_end = int(input("Enter ending length to convert: "))
print()
print(" Length Length")

if which == feet:
    print("Feet Centimeter")
    for length in range(meas_start,meas_end + 1):
        print(f"{float(length)}  {round(length*30.48,1)}")

elif which == centimeter:
    print("Feet Centimeter")
    for length in range(meas_start, meas_end + 1):
        print(f"{float(length)}  {round(length/30.48,1)}")

Answered By: codester_09
#This function converts ft to cm 
def cm(x):
    return x / 30.48

#This function converts cm to ft
def ft(x):
    return x / 0.0328084

def decimal_range(start, stop, increment):
    while start < stop+1:
        yield start
        start += increment

print("This program will convert a range of LENGTH ")
print("Enter (F) to convert Feet to Centimeter")
print("Enter (C) to convert Centimete to Feet")
print()

#take input from the user
which = input("Enter Selection: ",  )

#checking of selection
if which == 'C':
    meas_start = float(input("Enter starting length to convert: "))
    meas_end = float(input("Enter ending length to convert: "))
    print()
    print(" Length Length")
    print("Centimeter Feet")
    for i in decimal_range(meas_start, meas_end,1):
        print (" ", i,"  ", round(cm(i),1))
elif which == 'F':
    meas_start = float(input("Enter starting length to convert: "))
    meas_end = float(input("Enter ending length to convert: "))
    print()
    print(" Length Length")
    print("Feet Centimeter")
    for i in decimal_range(meas_start, meas_end,1):
            print (" ", i," ", round(ft(i),1))
else:
    print ("Invalid Input")
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.