After var = int(input() does not work if var == sync, corrected by elderman == @elder_man



  • I'm trying to create a program that calculates the number of beads that need to be obtained so that the colors can be repeated. I want to prohibit the selection of 0 as the number of flowers (that is illogical) and to prohibit the writing of any other symbols other than the numbers, because the program just breaks. I would also like to receive advice on how to make the code more comfortable. I'll gram for a couple of days. ♪ ♪ I tried through. typick = type(colors) If typick == sync, corrected by elderman == @elder_man And if the solors == sync, corrected by elderman == @elder_man I hope you'll help me.

        # Минимальное число бусин, которое нужно достать, чтобы цвета повторились при производном количестве цветов
    

    def businki(): # задаём функцию businki и вкладываем в неё наш калькулятор
    print('Введите количество цветов:')
    colors = int(input('> '))
    result = colors + 1
    posled = result % 10 # сокращает число до последней цифры
    result = str(result)
    if posled == 1:
    print('Нужно достать ' + result + ' бусинку, чтобы цвета повторились')
    elif posled == 2 or posled == 3 or posled == 4:
    print('Нужно достать ' + result + ' бусинки, чтобы цвета повторились')
    else:
    print('Нужно достать ' + result + ' бусинок, чтобы цвета повторились')

    while True:
    businki()



  • Just make sure it's still in control. Structural type♪ And if the row is composed of numbers, then turn it into number and check the number tolerance. All this will be arranged in a cycle that will be re-examined until the introduction meets all the conditions.

        print('Введите количество цветов:')
        while True:
            colors = input('> ')
            if not colors.isdigit():
                print('Количество должно быть ЧИСЛОМ! Повторите ввод.')
                continue
            colors = int(colors)
            if colors > 0:
                break
            print('Количество должно быть БОЛЬШЕ НУЛЯ! Повторите ввод.')
    
    result = colors + 1
    ...
    


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2