Category «For loop»

Lost card

Lost card. You have a set of cards numbered from 1 to N. One card is missing. Given the number N followed by N-1 distinct integers representing the numbers on the remaining cards, determine and print the number on the missing card. Test Case Input (N and remaining cards) Expected Output 1 5 1 2 …

Number of primes in range

Number of primes in range. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Given two integers A and B, print the number of prime numbers between them, inclusive. Test Case Input (A and B) Expected Output 1 3 10 3 2 10 20 …

Print primes in range

Print primes in range. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Given two integers A and B, print all prime numbers between them, inclusive.  

Is prime

Is prime. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Given an integer N greater than 1, print “PRIME” if it is a prime number, and print “COMPOSITE” otherwise. Test Case Input (N) Expected Output 1 2 PRIME 2 4 COMPOSITE 3 17 …

Ladder

Ladder. Given an integer n (where n ≤ 9), print a ladder of n steps. The k-th step consists of the integers from 1 to k without spaces between them. Use the sep and end arguments in the print() function to achieve this. Test Case Input (n) Expected Output 1 3 1 12 123 2 …

Squares in range

Squares in range. Given two integers A and B, print the squares of all integer numbers between them in the format x*x=y, where x is the integer and y is its square. Ensure there are no spaces around the * and = symbols. The sep argument of the print() function can help achieve this. Test Case …

Adding factorials

Adding factorials. Given an integer n, calculate and print the sum of the factorials from 1! to n!: 1! + 2! + 3! + … + n! This problem can be solved using only one loop. Do not use the math library. Test Case Input (n) Expected Output 1 3 9 2 4 33 3 …

The number of zeros

The number of zeros. Given a series of N numbers where the first number in the input specifies N, followed by N integers, count how many of these integers are zero and print the count. Note that you need to count the number of integers that are equal to zero, not the number of zero …

Factorial

Factorial. In mathematics, the factorial of an integer n, denoted by n!, is the product of all positive integers from 1 to n: n! = 1 × 2 × … × n For a given integer n, calculate the value of n! without using the math module. Test Case Input (n) Expected Output 1 3 …

Sum of cubes

Sum of cubes. Given an integer N, calculate the sum of cubes of all integers from 1 to N: 13 + 23 + … + N3 Test Case Input (N) Expected Output 1 3 36 2 4 100 3 5 225