Writing a simple module.Write the missing code in the below program that defines a few functions and variables.Follow the given instructions :The below program has a List of subjectsTwo functions are defined with the names arithmetic-operations and comp-operations with two arguments num1 and num2Perform all arithmetic and comparison operations in the comment lines given in the program.Print the len of courses list by calling the function __len__()Print the result as shown in the exampleSample Input and Output:addition: 30subtraction: -10multiplication: 200division: 0.5is greater: Falseis less than: Trueis equal to: Falseis not equal to: Truelength: 4
Question
Writing a simple module.Write the missing code in the below program that defines a few functions and variables.Follow the given instructions :The below program has a List of subjectsTwo functions are defined with the names arithmetic-operations and comp-operations with two arguments num1 and num2Perform all arithmetic and comparison operations in the comment lines given in the program.Print the len of courses list by calling the function len()Print the result as shown in the exampleSample Input and Output:addition: 30subtraction: -10multiplication: 200division: 0.5is greater: Falseis less than: Trueis equal to: Falseis not equal to: Truelength: 4
Solution
Here is the Python code that follows the instructions given in the question:
# List of subjects
courses = ['Math', 'Science', 'English', 'History']
# Function to perform arithmetic operations
def arithmetic_operations(num1, num2):
print("addition:", num1 + num2)
print("subtraction:", num1 - num2)
print("multiplication:", num1 * num2)
print("division:", num1 / num2)
# Function to perform comparison operations
def comp_operations(num1, num2):
print("is greater:", num1 > num2)
print("is less than:", num1 < num2)
print("is equal to:", num1 == num2)
print("is not equal to:", num1 != num2)
# Call the functions
arithmetic_operations(20, 10)
comp_operations(20, 10)
# Print the length of the courses list
print("length:", len(courses))
This code first defines a list of subjects. Then it defines two functions: arithmetic_operations and comp_operations. The first function performs and prints the results of basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers. The second function performs and prints the results of comparison operations (greater than, less than, equal to, not equal to) on two numbers. Finally, the code calls these functions with the numbers 20 and 10 as arguments, and prints the length of the courses list.
Similar Questions
Write a program that does basic arithmetic operations (addition, subtraction, multiplication,and division). The inputs to the program are two numbers (in double format) and theoperation required. Provide a function for each operation and the identifiers for addition,subtraction, multiplication, and division are ‘+’, ‘-‘, ‘*’, and ‘/’ respectively
Writing a program using 'from' keyword along with importing asterisk (*).Write a program to calculates sum, average and final grade of a student using * in import.import all the functions from Module_Imp3.py using *.Taken the scores of a student as input from user.Calculate the sum of scores using the calculate_sum function by passing scores as argument.Calculate the average of scores using the calculate_average function by passing scores as argument.Determine the final grade based on the average score using the determine_grade function.Note: The Module_Imp3.py already is written. Just follow the above instructions and complete the program.Sample Test CasesTest Case 1:Expected Output:Enter·the·scores·separated·by·spaces:·90 85 70 60 75Sum·of·scores:·380.00Average·score:·76.00Final·grade:·CTest Case 2:Expected Output:Enter·the·scores·separated·by·spaces:·85.5 76.5 90.0 82.0 95.5Sum·of·scores:·429.50Average·score:·85.90Final·grade:·B
Write a program to enter two numbers and print the arithmeticoperations like +,-,*,**, /, // and % using function
Write a program that imports the function def add(a, b): from the file add_0.py and prints the result of the addition 1 + 2 = 3You have to use print function with string format to display integersYou have to assign:the value 1 to a variable called athe value 2 to a variable called band use those two variables as arguments when calling the functions add and printa and b must be defined in 2 different lines: a = 1 and another b = 2Your program should print: <a value> + <b value> = <add(a, b) value> followed with a new lineYou can only use the word add_0 once in your codeYou are not allowed to use * for importing or __import__Your code should not be executed when imported - by using __import__, like the example below
Correct the errors in the program below. It should:define a function thattakes in one parameter, a length in centimetresdivides the length by 2.54, and returns itasks the user for a length in centimetrespasses the length to the function, and outputs the result in the format "x cm is y inches", where x is the user's length and y is the result of the function
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.