Single File Programming QuestionProblem StatementAkil is looking to develop a program that identifies all the factors of a positive integer. The program should accept an integer 'n' as input, and then output all of its factors, while also classifying them as either odd or even. This task should be accomplished using a for loop.For example, the factors of number 15 are calculated as follows:1 * 15 = 153 * 5 = 155 * 3 = 1515 * 1 = 151, 3, 5, and 15 are the factors of 15.Odd factors are 1, 3, 5, and 15. There are no even factors.Note: This question helps in clearing technical coding tests for service-based companies.Input format :The input consists of an integer n for which the factors need to be calculated.Output format :The first line prints "Factors: " followed by the factors for the given number as integers, separated by a space.The second line prints "Odd factors: " followed by the odd factors for the given number as integers, separated by a space.The third line prints "Even factors: " followed by the even factors for the given number as integers, separated by a space.If there are no even factors present, the third line prints "Even factors: Unavailable".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:2 ≤ n ≤ 10000Sample test cases :Input 1 :10000Output 1 :Factors: 1 2 4 5 8 10 16 20 25 40 50 80 100 125 200 250 400 500 625 1000 1250 2000 2500 5000 10000 Odd factors: 1 5 25 125 625 Even factors: 2 4 8 10 16 20 40 50 80 100 200 250 400 500 1000 1250 2000 2500 5000 10000 Input 2 :15Output 2 :Factors: 1 3 5 15 Odd factors: 1 3 5 15 Even factors: UnavailableInput 3 :2Output 3 :Factors: 1 2 Odd factors: 1 Even factors: 2 Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case
Question
Single File Programming QuestionProblem StatementAkil is looking to develop a program that identifies all the factors of a positive integer. The program should accept an integer 'n' as input, and then output all of its factors, while also classifying them as either odd or even. This task should be accomplished using a for loop.For example, the factors of number 15 are calculated as follows:1 * 15 = 153 * 5 = 155 * 3 = 1515 * 1 = 151, 3, 5, and 15 are the factors of 15.Odd factors are 1, 3, 5, and 15. There are no even factors.Note: This question helps in clearing technical coding tests for service-based companies.Input format :The input consists of an integer n for which the factors need to be calculated.Output format :The first line prints "Factors: " followed by the factors for the given number as integers, separated by a space.The second line prints "Odd factors: " followed by the odd factors for the given number as integers, separated by a space.The third line prints "Even factors: " followed by the even factors for the given number as integers, separated by a space.If there are no even factors present, the third line prints "Even factors: Unavailable".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:2 ≤ n ≤ 10000Sample test cases :Input 1 :10000Output 1 :Factors: 1 2 4 5 8 10 16 20 25 40 50 80 100 125 200 250 400 500 625 1000 1250 2000 2500 5000 10000 Odd factors: 1 5 25 125 625 Even factors: 2 4 8 10 16 20 40 50 80 100 200 250 400 500 1000 1250 2000 2500 5000 10000 Input 2 :15Output 2 :Factors: 1 3 5 15 Odd factors: 1 3 5 15 Even factors: UnavailableInput 3 :2Output 3 :Factors: 1 2 Odd factors: 1 Even factors: 2 Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case
Solution
Here is a Python solution for the problem:
def find_factors(n):
factors = []
odd_factors = []
even_factors = []
for i in range(1, n + 1):
if n % i == 0:
factors.append(i)
if i % 2 == 0:
even_factors.append(i)
else:
odd_factors.append(i)
return factors, odd_factors, even_factors
n = int(input())
factors, odd_factors, even_factors = find_factors(n)
print("Factors: ", end="")
for factor in factors:
print(factor, end=" ")
print()
print("Odd factors: ", end="")
for odd_factor in odd_factors:
print(odd_factor, end=" ")
print()
if len(even_factors) == 0:
print("Even factors: Unavailable")
else:
print("Even factors: ", end="")
for even_factor in even_factors:
print(even_factor, end=" ")
print()
This program works by iterating over all numbers from 1 to n and checking if n is divisible by the current number. If it is, the current number is a factor of n and is added to the list of factors. If the factor is even, it is also added to the list of even factors. If the factor is odd, it is added to the list of odd factors. After all factors have been found, they are printed out. If no even factors were found, "Even factors: Unavailable" is printed.
Similar Questions
Single File Programming QuestionProblem StatementBeula is solving a mathematical problem and seeks your assistance in writing a program. She is particularly interested in finding numbers with exactly 9 factors. Help her by creating a program that takes an integer N as input and identifies numbers from 1 to N that have exactly 9 factors.Function Specifications:check_9_factors - Prints the integers that have exactly 9 divisors as well as the total number of such integers.Note: This question helps in clearing technical coding tests for companies like Infosys.Input format :The input consists of an integer N.Output format :The first line displays space-separated integers representing numbers from 1 to N that have exactly 9 factors.The second line displays a single integer representing the count of numbers with exactly 9 factors.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:100 ≤ N ≤ 1500Sample test cases :Input 1 :100Output 1 :36 100 2Input 2 :150Output 2 :36 100 2Input 3 :1500Output 3 :36 100 196 225 256 441 484 676 1089 1156 1225 1444 12Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Problem StatementAnna is working on a program to find common factors of two unsigned integers. Design a program that:Takes two unsigned integers: n1 and n2, as input.Identifies and prints all common factors of these numbers.For example, Let us take two numbers 24 and 36. The factors of 24 are 1, 2, 3, 4, 6, 8, 12, 24. The factors of 36 are 1, 2, 3, 4, 6, 9, 12, 36. The common factors of 24 & 36 are 1,2,3,4,6,12 Ensure the program accurately identifies common factors, providing correct results for various inputs.Input format :The input consists of two unsigned integers n1 and n2 separated by a space.Output format :The output prints the common factors of n1 and n2, separated by a space.
Alice, an avid coder, utilizes the goto statement in her program. When she receives an input, if it's even, she employs goto to print its factors. Otherwise, she uses goto to display the next number of it. Write a program to achieve Alice's task.Input format :The input line consists of a single integer n, representing the number.Output format :If n is even:The first line displays "Even".The second line displays "Factors: " followed by the factors of n, separated by a space.If n is odd:The first line displays "Odd".The second line displays "Next number: " followed by the next number of n.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ n ≤ 100Sample test cases :
Subha is tasked with developing a program to analyze and categorize a large dataset of numerical data points.As a part of her program, she needs to identify and extract all the even numbers from the dataset, which ranges from 2 to a specified integer(inclusive).Help Subha to write this program using a 'for' loop.Input format :The input consists of an integer N.Output format :The output displays the even numbers in the dataset separated by space, till the specified integer.Refer to the sample output for formatting specifications.Code constraints :The given test cases fall under the following constraints:1 ≤ N ≤ 100Sample test cases :Input 1 :17Output 1 :2 4 6 8 10 12 14 16 Input 2 :6Output 2 :2 4 6
Single File Programming QuestionProblem StatementAmil, a curious coder, has a distinctive approach to handling numerical input. Write a program to get an integer from the user. If the number is even, the system employs a goto statement to a label indicating an affirmative response. Otherwise, another goto statement conveys a negative response.Input format :The input consists of a single integer n.Output format :The output displays one of the following:If n is an even number, it displays "You entered an even number."If n is an odd number, it displays "You entered an odd number."Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ n ≤ 100Sample test cases :Input 1 :1Output 1 :You entered an odd number.Input 2 :100Output 2 :You entered an even number.Input 3 :67Output 3 :You entered an odd number.
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.