# Second Exercises

# Find a sum until enter 0

OUTPUT

Enter number: 55 Enter number: 66 Enter number: 754 Enter number: 0 875.0

Solutions
sum=0
while(True):
    incoming=input("Enter number: ")
    if(incoming == "0"):
        break
    else:
        sum+=float(incoming)
print(sum)
1
2
3
4
5
6
7
8

or

data=[]
while(True):
    incoming=input("Enter number: ")
    if(incoming== "0" ):
        sum=0
        for number in data:
            sum+=number
        print(sum)
        break
    else:
        data.append(float(incoming))
1
2
3
4
5
6
7
8
9
10
11

# Find a sum average until enter "done"

OUTPUT

Enter a command: 12 Enter a command: 31 Enter a command: done avg: 21.5

OUTPUT

Enter a command: 534 Enter a command: 87 Enter a command: 23 Enter a command: 33 Enter a command: done avg: 169.25

Solution
sum=0
n=0
while(True):
    data=input("Enter Number: ")
    if(data!="done"):
        sum+=float(data)
        n+=1
    else:
        break
print(f"avg : {sum/n}")
1
2
3
4
5
6
7
8
9
10

# Find max value

OUTPUT

Enter a command: 12 Enter a command: 31 Enter a command: done max: 31.0

OUTPUT

Enter a command: -12 Enter a command: 60 Enter a command: 0 Enter a command: 5 Enter a command: done max: 60.0

OUTPUT

Enter a command: -12 Enter a command: -5 Enter a command: -20 Enter a command: -4 Enter a command: done max: -4.0

Solution
current_max = None
while True:
    data = input("Enter a command: ")
    if(data == "done"):
        break
    data = float(data)
    if(current_max is None):
        current_max = data
    if(data > current_max):
        current_max = data
print(f"max: {current_max}")
1
2
3
4
5
6
7
8
9
10
11