Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rerun = 'Y'
- # list to contain the inputted numbers
- numbers = []
- # program is in a while loop
- while rerun.upper() == 'Y':
- # input
- try:
- num = int(input('Task 1: Please give a number: '))
- # Error Message when character is not a number.
- except ValueError:
- print("Sorry. That is not a number. Restart the program.")
- quit()
- # Appends all the numbers made into a list made outside of while loop
- numbers.append(num)
- # computations as well as output
- # Even / Odd Computation: computes if even or odd using modulo
- even_odd = (num % 2)
- if even_odd == 1:
- print(f"Task 2: {num} is an odd number")
- elif even_odd != 1:
- print(f"Task 2: {num} is an even number")
- # Prime / Composite computation: computes if prime or composite
- # by determining whether the number has more than 2 factors
- if num > 1:
- # range( all numbers above 2, up until the given number divided by 2 + 1)
- for i in range(2, int(num / 2) + 1):
- if (num % i) == 0:
- print(f'Task 3: {num} is a composite number')
- break
- else:
- print(f'Task 3: {num} is a prime number')
- else:
- print(f'Task 3: {num} is neither a prime or composite number')
- # Variables for the biggest and smallest numbers
- biggest = max(numbers)
- smallest = min(numbers)
- # Variables for the average of the average of the total numbers
- totalNumbers = len(numbers)
- sumNum = sum(numbers)
- ave = float(sumNum) / float(totalNumbers)
- # computation for odd / even result without modulo use
- # a/2 computes with a decimal point while a//2 computes without decimal point.
- # They will not be equal if the number is odd hence the if else code syntax
- if num / 2 == num // 2:
- not_modulo = 'even'
- else:
- not_modulo = 'odd'
- print(f'Task 4: The highest number so far is {biggest}')
- print(f'Task 4: The lowest number so far is {smallest}')
- print(f'Task 5: The total sum of the entered numbers is: {sumNum}')
- print(f'Task 6: The average sum of all numbers enters is: {ave}')
- print(f'Task 7: The number {num} is {not_modulo} and is '
- f'computed without the use of the modulo "%" operator')
- rerun = input('Do you want to run the program again?'
- ' Press Y for yes. Press any other key for no : ')
- # Termination of program
- print('Goodbye! Program ended.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement