Skip to main content

Command Palette

Search for a command to run...

DAY 21 of PYTHON top 100 questions : from Basic to Advanced !!

Published
1 min read
DAY 21 of PYTHON top 100 questions : from Basic to Advanced !!
P

Hello, I'm Priya Chakraborty, a dedicated B.Tech student in Electrical Engineering at Siliguri Institute Of Technology. I'm an enthusiastic learner, constantly seeking to expand my skill set and knowledge base. With a solid foundation in programming languages such as C, R, Python, and MySQL, I'm poised to tackle complex technical challenges.

But my passions extend beyond the realm of engineering. I'm also an aspiring content writer, driven by a curiosity to communicate ideas, both technical and non-technical, in a way that captivates and educates.

My journey is defined by a relentless pursuit of self-improvement, coupled with strong communication skills. I believe in the power of continuous learning and the importance of sharing knowledge.

Write a Python program to find the missing number in a given array of integers.

array = [1,2,3,4,5,7,8,9]
n = len(array) + 1
total_sum = (n * (n + 1)) // 2
array_sum = sum(array)
missing_number = total_sum - array_sum
print(missing_number)

Output :

6

The code calculates the missing number in a given array of integers. It does so by finding the sum of integers from 1 to n, where n is the length of the array plus one. Then, it calculates the sum of the given array. The missing number is obtained by subtracting the array sum from the total sum of integers. Finally, the code prints the missing number.


If you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).


HAPPY LEARNING !!!

More from this blog

Priya's blog

46 posts

Python Developer@Codeclause Mentee @Trailhead Salesforce Content Executive @GDSC SIT'22-23 Google Women Techmakers Ambassador @Google WTM Coreteam @ GirlScript Kolkata