Question
PYTHON 3!!!! I'm writing a program to tell whether something is divisible by 7 and im getting confused between the string and intergers forms of
PYTHON 3!!!! I'm writing a program to tell whether something is divisible by 7 and im getting confused between the string and intergers forms of my input.
here is the question and below it is the code that I have now
def q1d(Interger): number = int(Interger) stepone = (Interger[-1]*2) steptwo = (Interger[0:1]- stepone) step3 = steptwo[-1] * 2 step4 = 7-step3 list = [number, step4] if (number Question 1d: One method to determine if an Integer is a multiple of 7 is to double the last digit and subtract it from the remaining leading truncated Integer. Apply this rule over and over again till you reach a single digit. The original Integer is divisible by 7 if the absolute value of the result is divisible by 7, or if it is zero For example, consider the Integer. 826 6*2=12 82- 1270 The last digit is 6, double this digit: Subtract 12 from the leading Integer, 82 The last digit is 0, double this digit: Subtract 0 from the leading Integer 7 . . The final value is a single digit of 7, therefore the original Integer 826 is divisible by 7. Write a function named qld) that accepts an Integer as a parameter then: Using only String manipulation and Integer subtraction, follow the method described above to determine if the Integer is a multiple of 7. You may not use modulus operator Create a List so that the first element is either True or False depending on whether the parameter Integer was divisible by 7 or not. If the starting parameter is zero (0) or is not an Integer, the function returns [False] . The second element of the List should be the starting parameter (if it is an Integer) . The rest of the List elements will contain the results of subtracting the doubled digits from the remaining leading Integers (see examples below) Once the evaluation process is complete, the qld ) function should return the List Example Input/ Output: >>>qld (0) False] >>> qld ('hello') [False] >>> qld(14) [True, 14, 7 >>>qld (91) [True, 91, 71 >>> qld(154) [True, 154, 7 >>>qld (323) [False, 323, 26, 10, 1] >>>qld (1800) [False, 1800, 180, 18, 15, 9] >>> qld (2499) [True, 2499, 231, 21, 0] Note: The function returns the List - it does not print anything
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started