Question

In: Computer Science

Develop and test a Python program that converts pounds to grams, inches to centimeters, and kilometers...

Develop and test a Python program that converts pounds to grams, inches to centimeters, and kilometers to miles. The program should allow conversions both ways.

Solutions

Expert Solution

please go through screenshots for better understanding.Any comments below.Thank you.

python code:

def poundsTograms(pounds): #implementing pundsTograms method
grams = pounds /0.00220462 # calculating grams
return grams

def inchesTocm(inches): # implemeting inchesTocm method
cm = inches*2.54 #calculating centimeters
return cm

def kmTomiles(km): #implementing kmTomiles method
miles = km*0.621371 #calculating miles
return miles

def gramsTopounds(grams): #implementing gramsTopounds method
pounds = grams*0.00220462 #calculating pounds
return pounds

def cmToinches(cm): #implementing cmToinches method
inches = cm/2.54 # calculating inches
return inches

def milesTokm(miles): #implementing milesTokm method
km = miles/0.621371 #calculating kilometers
return km

#prompting user to enter option
c = int(input("enter optiion\n1.pounds to grams\n2.inches to centimeters\n3.kilometers to miles\n4.grams to pounds\n5.centimeters to inches\n6.miles to kilometers\n"))

if c==1:
p = float(input("enter pounds:")) #reading input from user
print(p," punds = ",poundsTograms(p)," grams") #printing result
  
elif c==2:
i = float(input("enter inches:"))#reading input from user
print(i," inches = ",inchesTocm(i)," cms") #printing result
  
elif c==3:
km = float(input("enter kilometers:"))#reading input from user
print(km," kilometers = ", kmTomiles(km)," miles") #printing result
  
elif c==4:
grams = float(input("enter grams:"))#reading input from user
print(grams,"grams = ",gramsTopounds(grams)," pounds") #printing result
  
elif c==5:
cm = float(input("enter centimeters:"))#reading input from user
print(cm," centimeters = ",cmToinches(cm)," inches") #printing result
  
elif c==6:
miles = float(input("enter miles:"))#reading input from user
print(miles," miles = ",milesTokm(miles)," kms") #printing result
else:
print("Invalid option")

lll


Related Solutions

In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
You are to develop a program of exercise and diet to lose 10 pounds in the...
You are to develop a program of exercise and diet to lose 10 pounds in the course of 5 weeks based on your current body weight. If you don't want to reveal your weight make one up. Start with your current calorie need per day. Include calories for daily exercise and amount of calories you need to restrict per day.  
Using Python Write a GUI program that converts a distance in Meters to the equivalent distance...
Using Python Write a GUI program that converts a distance in Meters to the equivalent distance in Feet. The user should be able to enter a distance in Meters, click a button, and then see the equivalent distance in feet. Use the following formula to make the conversion: Meters = Feet x 0.304 For example, 1 Meter is 3.28 Feet.
IN PYTHON Develop a program in python that includes a number of functions for the multi-server...
IN PYTHON Develop a program in python that includes a number of functions for the multi-server queue. The program accepts arrival and services rates and the number of servers and calls your functions to output the average number of customers and average waiting time in the system.
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
PYTHON: Turtle Command Interpreter You will write a program that reads a sequence of codes, converts...
PYTHON: Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them into Turtle commands, and then executes them. The codes are in a Python list, passed as an argument to your function. turtleRunner(t, x) t is a Turtle x is a list of Turtle commands Code List (f, d)    Move forward by d pixels u Lift pen up d Put pen down (l, d) Turn left by d degrees (r, d) Turn right...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in...
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert.
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert. (Note: 1 inch = 2.54 cm. Do not modify function main.) #include #include using namespace std;// Write your function prototype here.int main(){ double measurement; cout ≪ "Enter a length in inches, and I will convert\n"; cout ≪ "it to centimeters: "; cin ≫ measurement; convert(&measurement); cout...
Write, save, and run a Python program Ask the user to enter a number of grams....
Write, save, and run a Python program Ask the user to enter a number of grams. Your program converts that to whole tones, then whole kilograms and whatever is left is in grams. It prints the entered grams , tones , kilograms and the remaining grams.      4 marks for i in range(0,10): print(i) 2    what is wrong in the above python code? display your explanation using print statement. mark 3    insert the following comments into your program of part...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT