I am working on a project were the user inputs a number and a list, and whatever item in the list is closest to the number, is printed out. I have come across a problem were the line in my if() statement in my while loop is running every time? I have a feeling it has something to do with indenting if() statements in python 3 but I am not certain. Anybody know why this is happening?
import math
MatchingI = math.inf
while i < len(compareList):
if (abs(int(mainNum) - int(compareList[i])) < MatchingI):
MatchingI = int(compareList[i])
i += 1
Aucun commentaire:
Enregistrer un commentaire