Question

In: Computer Science

PYTHON Basic feature [7pts]Write a functionto perform unit conversion between kilograms(kg) and pounds (lb) (1 kg=...

PYTHON

Basic feature [7pts]Write a functionto perform unit conversion between kilograms(kg) and pounds (lb) (1 kg= 2.205 lb). The function takes 2 arguments—unit (kgor lb) and measurement—and printsthe converted valuedirectly inside the function.

Additional Features [4pts]

1.The function prints an error message when an inappropriate unit (e.g., abc) is used.Also,the function is non-case-sensitive tothe unit argument (e.g., should run properly with “Kg” or “kG” too).

2.Print the original input together with the converted value. Units must be printed in uppercase

Solutions

Expert Solution

Python code:

#defining function to convert between units
def convert(val,unit):
#checking if the unit is kg
if(unit.lower()=='kg'):
#printing the value and the converted value
print("{} KG = {} LB".format(val,val*2.205))
#checking if the unit is lb
elif(unit.lower()=='lb'):
#printing the value and the converted value
print("{} LB = {} KG".format(val,val/2.205))
else:
#printing Error
print("Error inappropriate unit")
#calling convert function for sample kg value
convert(10,'kG')
#calling convert function for sample lb value
convert(22.05,'lb')
#calling convert function for sample inappropriate value
convert(10,'abc')


Screenshot:


Input and Output:


Related Solutions

PYTHON Basic Feature[5pts] Write a function which takes two arguments—a string (str1) and a position index...
PYTHON Basic Feature[5pts] Write a function which takes two arguments—a string (str1) and a position index (n). The function will: 1.Remove the n-th characterof str1 (the initial character is the 0-th character) 2.Swap the order of the substring in front of the removed character and the substring afterwards, and concatenate them as a new string 3.Return the converted (str2) back to the function caller For example, myfunc(“abc1xyz”, 3) returns “xyzabc”. Additional Features [6 pts] Expand the function by adding more...
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to...
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to binary and gray scale, Image segmentation and extraction, draw and find the region of interest with a circle, Plot bounding box, Region extraction and histogram. 2- Write a MATLAB program to Design a GUI calculator which is as shown in below figure 1. Add tool bar options to the GUI calculator and Highlight specific codes written in program and signify the steps followed.
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
1. Write a python function that receives two positive numbers and displays the prime numbers between...
1. Write a python function that receives two positive numbers and displays the prime numbers between them.Note: A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors other than 1 and itself. 2. Using either Whileor Foriteration loops, write a python code that prints the first Nnumbers in Fibonacci Sequence, where N is inputted by the user. Now, revise this code to instead print a) the Nthnumber in Fibonacci Sequence.b) the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT