関数の基礎練習

10327 ワード

関数の基礎練習
#     , 1+2+3+…N  
def sum1(n):
    a = 0
    for i in range(0,n+1):#  range     
        a += i
    return a
print(sum1(5))
#       ,         
num = input("      :")
num1 = num.split(' ')#        ,       
print(num1)
def max1():
    a = num1[0]#       0     ,    
    for i in num1:
        if i > a:#     ,     a
            a = i
    return a
print(max1())
#       ,        ,  N       
import random
def sz(n):
    a = 0
    for i in range(1,n+1):
        b = random.randint(1,7)
        a += b#          a
    return a
print(sz(4))
#       ,       key value
dict1 = {
     'a':1, 'b':2, 'c':3}.items()#  item          
def change():
    dict_new = {
     }#           
    for a,b in dict1:#         
        x = b
        y = a
        dict_new[x] = y#         
    print(dict_new)
change()
#       ,             ,                
str1 = input("        :")
def new():
    str2 = ''#      
    for i in str1:
        if i.isalpha() == True:#              
            str2 += i
    print(str2)
new()
#      ,        
def avg():
    sum1 = 0
    count = 0
    num = input("      :")
    num1 = num.split(' ')#     
    for i in num1:
        sum1 += int(i)
        count += 1
    print(sum1/count)
avg()
#      ,   10   ,           
def jc(n=10):#    
    for i in range(1,n):
        n *= i
    return n
print(jc())#    ,n    10