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
  • Last modified: 2023/11/13 08:56
  • by 127.0.0.1