So I'm taking a beginner Python class and one of my questions is to write code that takes n number (e.g. 5) and asks the user to enter n-1 numbers in n and finds the missing number. I can't use anything more advanced than loops.
For some reason even though the value of nn gets updated ever time the loop runs the value of number only decreases by 1 every time the loop runs.
n = int(input('Please enter n: '))
ntotal = int(n*(n+1)/2)
print ('Please enter n: ')
print (ntotal)
i = 0
k = i
while i != n-1:
nn = int(input('Please enter a number: '))
number = ntotal - nn
print (nn)
i += 1
print (number)
ntotal = ntotal - nnand at the end useprint(ntotal)ntotalsupposed to be? Whyprint('Please enter n: ')? Alsokis unused. Please make a minimal reproducible example.range? BTW welcome to Stack Overflow! Check out the tour.ntotal == sum(range(n+1))