0

I've been learning python in a couple weeks and doing some challenges. My question is: I'm gonna ask for 2 ints inputs from user and put on a list ''list = []'' if the user write the same value(int) I have to print a message like ''Denied, already on list'' that's my code so far:

list = []
yourn = ' ' #yesorno
while yorn != 'n': #condition to break the loop
    list.append(int(input('Insert a number: ')))
    
  *** #thats where I'm stucked
    ***for rep in list
    if rep not in lista:
        continue
    else:
        print('duplicate')****
** (I know that's no the right way, thats just me trying it out)
    yorn = str(input('Continue? [Y/N]: ')).strip().lower()[0]
print('END!')
print(f'The numbers are: {sorted(list)} ', end=' → ')

trying my best here! thanks!!

I tried 'for' loop to identify a repeat number and if to get the condition

Camponez
  • 1
  • 1
  • 1
    You could *first* check whether it is already in the list and *then* add it (if it is not yet). That would make things simpler – lucidbrot Dec 20 '22 at 19:19
  • By the way, don't name any variable as `list`, as this is a built-in python function – OneCricketeer Dec 20 '22 at 19:20
  • Thank you! I got it! I only used 'list as variable because I had to translate my code to help understanding the problem. – Camponez Dec 20 '22 at 19:51

0 Answers0