Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
930 B
5
Indexable
Never
#Bai 1
def DigitSum(s):
    sum = 0
    for i in s:
        sum += int(i)
    return sum
s = str(input())
print(DigitSum(s))

#Bai 3:
def Min_Max(datalist):
    print("Min = ", min(datalist))
    print("Max = ", max(datalist))
def Sum(datalist):
    sum = 0
    for i in datalist:
        sum+=float(i)
    print("Sum = ",sum)
def Average(datalist):
    sum = 0
    for i in datalist:
        sum+=float(i)
    print("Average = ",float(sum/len(datalist)))
with open('myfile.txt', 'r') as f:
    datalist = f.readlines()
if (len(datalist)!=0):
    Min_Max(datalist)
    Sum(datalist)
    Average(datalist)
else:
    print("Input n:")
    while(True):
        n = input()
        if (n.isdigit() and int(n)>0 and int(n)<100): break
    for i in range(0,int(n)):
        datalist.append(float(input()))
    Min_Max(datalist)
    Sum(datalist)
    Average(datalist)
"""
myfile.txt
1
2
3
"""