LU06.L12: Split in pieces

def main():
    print('Give a numbers:')
    number = 0
    while number != -1:
        number = int(input())
    print('Thx! Bye!')
 
 
if __name__ == '__main__':
    main()
def main():
    print('Give a numbers:')
    number = 1 # To compensate for -1 for terminating
    sum = 0
    while number != -1:
        number = int(input())    
        sum += number
    print('Thx! Bye!')
    print(f'Sum: {sum}')
 
 
if __name__ == '__main__':
    main()
def main():
    print('Give a numbers:')
    number = 1 # To compensate for -1 for terminating
    sum = 0
    counter = -1  # We start with -1 to compensate for last iteration
    while number != -1:
        number = int(input())
        sum += number
        counter += 1
    print('Thx! Bye!')
    print(f'Sum: {sum}')
    print(f'Numbers: {counter}')
 
 
if __name__ == '__main__':
    main()
def main():
    print('Give a numbers:')
    number = 1 # To compensate for -1 for terminating
    sum = 0
    counter = -1  # We start with -1 to compensate for last iteration
    while number != -1:
        number = int(input())
        sum += number
        counter += 1
    average = sum / counter
    print('Thx! Bye!')
    print(f'Sum: {sum}')
    print(f'Numbers: {counter}')
    print(f'Average: {average}')
 
 
if __name__ == '__main__':
    main()
def main():
    print('Give a numbers:')
    number = 0
    sum = 1
    counter = -1  # We start with -1 to compensate for last iteration
    odd = 0
    even = 0
    while number != -1:
        number = int(input())
        if (number % 2 == 0 and number > 0):
            even += 1
        if (number % 2 == 1 and number > 0):
            odd += 1
        sum += number
        counter += 1
    average = sum / counter
    print('Thx! Bye!')
    print(f'Sum: {sum}')
    print(f'Numbers: {counter}')
    print(f'Average: {average}')
    print(f'Even: {even}')
    print(f'Odd: {odd}')
 
 
if __name__ == '__main__':
    main()
  • modul/archiv/m319python/learningunits/lu06/loesungen/splitinpieces.txt
  • Zuletzt geändert: 2024/03/28 14:07
  • von 127.0.0.1