Snakify Python Program Solution For Loop with Range | Chetan TM

# 1) Series - 1

## Statement: Given two integers A and B (A ≤ B). Print all numbers from A to B inclusively.

Model solution

• a = int(input())
• b = int(input())
• for i in range(a, b + 1):
• print(i)

# 2) Series - 2

## Model solution

• a = int(input())
• b = int(input())
• if a < b:
• for i in range(a, b + 1):
• print(i)
• else:
• for i in range(a, b - 1, -1):
• print(i)

# 3) Sum of ten numbers

## Statement: 10 numbers are given in the input. Read them and print their sum. Use as few variables as you can.

Model solution

• res = 0
• for i in range(10):
• res += int(input())
• print(res)
OR
• # sum = 0
• # for i in range(10):
• # num = int(input("Input: "))
• # sum+=num
• # print(sum)

# 4) Sum of N numbers

## Model solution

• n = int(input())
• res = 0
• for i in range(n):
• res += int(input())
• print(res)
OR
• # item = int(input("Input: "))
• # sum = 0
• # for i in range(item):
• # num = int(input("Input: "))
• # sum+=num
• # print(sum)

# 5) Sum of cubes

## Model solution

• res = 0
• for i in range(1, int(input()) + 1):
• res += i ** 3
• print(res)
OR
• # num = int(input("Input: "))
• # cube = 0
• # for i in range(num+1):
• # cube+=(i*i*i)
• # print(cube)

# 6) Factorial

## For the given integer nn calculate the value n!n!. Don't use `math` module in this exercise.

Model solution

• res = 1
• n = int(input())
• for i in range(1, n + 1):
• res *= i
• print(res)
OR
• # # num = int(input("Input: "))
• # # fact = 1
• # # for i in range(1, num+1):
• # # fact*=i
• # print(fact)

# 7) The number of zeros

## Statement: Given N numbers: the first number in the input is N, after that N integers are given. Count the number of zeros among the given integers and print it.

You need to count the number of numbers that are equal to zero, not the number of zero digits.

Model solution

• num_zeroes = 0
• for i in range(int(input())):
• if int(input()) == 0:
• num_zeroes += 1
• print(num_zeroes)
OR
• # num = int(input("Input: "))
• # zero = 0
• # for i in range(num):
• # num = int(input("Input: "))
• # if num == 0:
• # zero+=1
• # else:
• # pass
• # print(zero)

## Statement: Given an integer nn, print the sum 1!+2!+3!+...+n!1!+2!+3!+...+n!.

This problem has a solution with only one loop, so try to discover it. And don't use the math library :)

Model solution

• n = int(input())
• partial_factorial = 1
• partial_sum = 0
• for i in range(1, n + 1):
• partial_factorial *= i
• partial_sum += partial_factorial
• print(partial_sum)
OR
• # num = int(input("Input: "))
• # sum = 0
• # fact = 1
• # for i in range (1, num+1):
• # fact*=i
• # sum+=fact
• # print(sum)

Name

ltr
item
Chetan TM: Snakify Python Program Solution For Loop with Range
Snakify Python Program Solution For Loop with Range
Python - Programming Language Snakify.org - Problem Solution For Loop with Range. 1) Series - 1. 2) Series - 2. 3) Sum of ten numbers. 4) Sum of N num
https://1.bp.blogspot.com/-V3BNVVeQkYQ/YGFV1QsfRSI/AAAAAAAAChc/JDfWB1A07hsZKhwbFOXbuGPGKTjWH-vuQCLcBGAsYHQ/s16000/Capture.PNG
https://1.bp.blogspot.com/-V3BNVVeQkYQ/YGFV1QsfRSI/AAAAAAAAChc/JDfWB1A07hsZKhwbFOXbuGPGKTjWH-vuQCLcBGAsYHQ/s72-c/Capture.PNG
Chetan TM
http://www.chetantm.com.np/2021/03/snakify-for-loop-with-range-python-program-solutions.html
http://www.chetantm.com.np/
http://www.chetantm.com.np/
http://www.chetantm.com.np/2021/03/snakify-for-loop-with-range-python-program-solutions.html
true
5092578752892144998
UTF-8