38.0k views
5 votes
Ask the user to enter a number n >= 1. There after the user will enter n-1 distinct integers between 1 and n. Thus, the entered numbers contain all numbers between 1 and n except one. Output the missing number. You are not allowed to use lists. You are also not allowed to use dictionaries or any programming concept more advanced that a loop. The numbers entered can be in any order.

User Demonplus
by
8.4k points

1 Answer

0 votes

Answer:

Code below

Step-by-step explanation:

n = int(input('Please enter n: '))#take input n

print('please enter the numbers')#print enter the numbers

total = 0 #intially take total as 0

original_total = 1 #intially take original_total=1

for i in range(2, n+1): #take the range 2 to n+1

total += int(input('Please enter a number: ')) # add total and enter the number

original_total += i

missing = original_total - total #you got missing number original_total - total

print('The missing number is: ' + str(missing)) # print missing number in the given data

User KallDrexx
by
7.8k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.