Please answer this question using python programming only and provide a screen short for this code.
Homework 3 - Multiples not less than a number
Question 1 (out of 3)
This homework is a SOLO assignment. While generally I encourage you to help one another to learn the material, you may only submit code that you have composed and that you understand.
Use this template to write a Python 3 program that
calculates the nearest multiple of a number that is not less than a
factor. Your program should get two arguments from the command line
and pass them to a function called get_nearest_multiple() -- this
part has been written for you. You need to write a function
get_nearest_multiple() that takes two integer arguments, in the
following order: a minimum number and a factor. Your function
should return an integer that is the smallest multiple of the
factor that is not less than the minimum number. You can assume
that the minimum number will not be negative and that the factor
will be positive.
Special requirements
Sample output
Below is a sample of what your Python script's output might look like.
$ python3 abills-inst326-homework3-q1.py 15 10
20
Here are a few more test cases:
assert get_nearest_multiple(0, 1) == 0
assert get_nearest_multiple(15, 7) == 21
assert get_nearest_multiple(435, 10) == 440
assert get_nearest_multiple(435, 200) == 600
assert get_nearest_multiple(10, 435) == 435
assert get_nearest_multiple(200, 435) == 435
Below is the copy of the template we are ask to use from the instruction above.
# your header here
"""Your docstring here"""
import argparse
import sys
# your function(s) here
def parse_args(arglist):
"""
Process command-line arguments.
Args:
arglist (list of str): arguments passed to the script from the
command line.
Returns:
args (obj): an object with attributes min_val (int) and
factor (int).
Raises:
argparse.ArgumentError: if min_val is negative or factor is less
than one.
Side effects:
if arglist contains '-h', parser.parse_args() will print a help
statement and exit.
if arglist does not match the arguments expected by the argument
parser, parser.parse_args() will print a short usage
statement and exit.
"""
# set up the argument parser
parser = argparse.ArgumentParser(
description="Given two values, min_val and factor, find the smallest"
" value >= min_val that is a multiple of factor."
)
parser.add_argument('min_val', type=int,
help='result should be no less than this number')
parser.add_argument('factor', type=int,
help='return value should be a multiple of this number')
# parse the command-line arguments
args = parser.parse_args(arglist)
# validate arguments
if args.min_val < 0:
raise argparse.ArgumentError('min_val must be greater than 0')
if args.factor < 1:
raise argparse.ArgumentError('factor must be greater than 1')
# return arguments
return args
if __name__ == '__main__':
args = parse_args(sys.argv[1:])
nearest_multiple = get_nearest_multiple(args.min_val, args.factor)
print(nearest_multiple)
'''
Python version : 3.6
Python program to create a function to get nearest multiple
'''
import argparse
import sys
# function that returns the smallest multiple of factor starting
from min_val
def get_nearest_multiple(min_val, factor):
i = min_val # set i to min_val
# loop that continues till we get the multiple
while True:
if( i%factor == 0): # if i is
divisible by factor, return i
return i
i += 1 # increment i
def parse_args(arglist):
"""
Process command-line arguments.
Args:
arglist (list of str): arguments passed to the script
from the
command line.
Returns:
args (obj): an object with attributes min_val (int)
and
factor (int).
Raises:
argparse.ArgumentError: if min_val is negative or
factor is less
than one.
Side effects:
if arglist contains '-h', parser.parse_args() will
print a help
statement and exit.
if arglist does not match the arguments expected by
the argument
parser, parser.parse_args() will print a short
usage
statement and exit.
"""
# set up the argument parser
parser = argparse.ArgumentParser(description="Given
two values, min_val and factor, find the smallest value >=
min_val that is a multiple of factor.")
parser.add_argument('min_val', type=int,help='result
should be no less than this number')
parser.add_argument('factor', type=int,help='return
value should be a multiple of this number')
# parse the command-line arguments
args = parser.parse_args(arglist)
# validate arguments
if args.min_val < 0:
raise
argparse.ArgumentError('min_val must be greater than 0')
if args.factor < 1:
raise
argparse.ArgumentError('factor must be greater than 1')
# return arguments
return args
if __name__ == '__main__':
args = parse_args(sys.argv[1:])
nearest_multiple = get_nearest_multiple(args.min_val,
args.factor)
print(nearest_multiple)
assert get_nearest_multiple(0, 1) == 0
assert get_nearest_multiple(15, 7) == 21
assert get_nearest_multiple(435, 10) == 440
assert get_nearest_multiple(435, 200) == 600
assert get_nearest_multiple(10, 435) == 435
assert get_nearest_multiple(200, 435) == 435
#end of program
Code Screenshot:



Please answer this question using python programming only and provide a screen short for this code....
This is for programming using Python with the JES software. Please write the code with the proper indentation. Thanks! Problem 1: Write a function that takes 2 arguments (integer or float) and computes the sum, difference, product, and quotient of the arguments. Once you calculate the values you should print out statements telling the user what arguments we used to compute the values and what the result of each calculation (your function should produce 5 lines of output in the...
Please write this code in python programming and provide a screen short of the code. Reading: P4E 7; Tut 7.2, 7.2.1 Upload an original Python script that satisfies the following criteria: It has at least two functions Function 1: This function has one parameter, a string containing the path to an existing text file that will be read by your function Using a with statement, the function opens the file indicated by the parameter for reading The function counts the...
Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...
I need help programming this question using C language. This program uses input data entered in command line at the same time when the command or .exe file is entered. They are called command-line arguments. Because everything entered in command line is taken as a string, these arguments including the command itself or the .exe file name are stored in an array of char pointers, each pointer points to the first character of a string (i.e., argument). The inputs can...
Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the program. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return "January". If the parameter is 2, your function should return out "February", etc. def monthString(monthNum): """ Takes as input a number, monthNum, and returns the corresponding month name as a string. Example:...
*PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code function. Good answers will be rated with thumbs up! Please answer both parts. Thank you for your time. Question 3 - Suppose you have a file named numbers.csv which contains a bunch of integers, five per line of text, separated by commas. Write code below that will open the _le, read the numbers from it, and print the sum of all the even numbers...
The original code using the gets() function is written below. You need to do (a) change the provided code so that you now use fgets() function to obtain input from the user instead of gets(), (b) make any other necessary changes in the code because of using fgets() function, and (c) fill in the code for the execute() function so that the whole program works as expected (a simple shell program). Note: part c is already done, and the execute...
I am writing python code. I submitted an assignment but the professor said it was a modularization. Can you help me see what part of the code is modularization? Pseudocode: 1. Decalre MainMethod () function: # A. Parameters: Three numbers # B. Put the three numbers in reverse # 2. Main Program # A. Initialize Varibles # B. Accepts three values from the user # C. Invoke MainMethod () function, passing the three numbers as arguments in reverse # D....
Need help with Python (BinarySearch), code will be below after my statements. Thank you. Have to "Add a counter to report how many searches have been done for each item searched for." Have to follow this: 1) you'll create a counter variable within the function definition, say after "the top = len(myList)-1" line and initialize it to zero. 2) Then within the while loop, say after the "middle = (bottom+top)//2" line, you'll start counting with "counter += 1" and 3)...
For part one of this assignment, write a program (parse.c) that contains a function to parse a single line of input and and prints out the individual tokens. Part 1 - Single Line Parser For part one of this assignment, you will need to learn how to do some parsing (or more accurately--lexing a line, you do not have to check for correctness). You have previously done some parsing with the cycle count tool perhaps using functions such as strcmp....