Created
August 9, 2021 14:30
-
-
Save mhassanist/042bdefa862508d0ccb073581b7d1f03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Task 1: | |
#Write a program that asks the user for 3 numbers and outputs the average of the numbers. | |
''' | |
sum =0 | |
for i in range(1,4): | |
num = int(input('Enter number {}: '.format(i))) | |
sum += num | |
print('Average is: {}'.format(sum/3)) | |
''' | |
#Task 2: Let the program accept any number of inputs (not just 3) and stops when user enters -100. | |
''' | |
sum = 0 | |
count = 0 | |
while True: | |
num = int(input('Enter number {}: '.format(count))) | |
if num ==-100: | |
break | |
sum += num | |
count +=1 | |
print('Average is : {}'.format(sum/count)) | |
''' | |
#Task 3: If user enters a negative number, don’t add it while calculating the average. | |
''' | |
sum =0 | |
count=0 | |
while True: | |
num = int(input('Enter number {}: '.format(count))) | |
if num ==-100: | |
break | |
if num < 0: | |
continue | |
sum += num | |
count +=1 | |
print('Average is : {}'.format(sum/count)) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment