No products in the cart.

Write a python program to calculate …

CBSE, JEE, NEET, CUET

CBSE, JEE, NEET, CUET

Question Bank, Mock Tests, Exam Papers

NCERT Solutions, Sample Papers, Notes, Videos

Write a python program to calculate the average of first N odd numbers.
  • 3 answers

Pratishtha Shree 1 year, 1 month ago

Here's ur program in python: n=int(input("Enter the number")) i=0 num=1 sum=0 While i<n: sum+=num num+=2 i+=1 print(sum)

Pratishtha Shree 1 year, 1 month ago

Here's ur program in python: n=int(input("Enter the number")) i=0 num=1 sum=0 While i<n: sum +=num num +=2 i +=1 print(sum)

Abhinav Verma 1 year, 3 months ago

# Python from math import ceil, floor def odd_gte(num): """ Return the first odd value >= num """ num = ceil(num) k = num // 2 return 2*k + 1 def odd_lte(num): """ Return the first odd value <= num """ num = floor(num) k = (num + 1) // 2 return 2*k - 1 def odd_average(start, stop): """ Return the average of all odd numbers in the range Note: this follows standard Python range semantics, such that `stop` is not included in the range. """ first = odd_gte(start) last = odd_lte(stop - 1) return (first + last) / 2 print(odd_average(2, 101)) # 51.0
http://mycbseguide.com/examin8/

Related Questions

what is palindrone
  • 1 answers
Case study based question
  • 0 answers

myCBSEguide App

myCBSEguide

Trusted by 1 Crore+ Students

Test Generator

Test Generator

Create papers online. It's FREE.

CUET Mock Tests

CUET Mock Tests

75,000+ questions to practice only on myCBSEguide app

Download myCBSEguide App