函数基础练习
def sum1(n):
a = 0
for i in range(0,n+1):
a += i
return a
print(sum1(5))
num = input("请输入多个数:")
num1 = num.split(' ')
print(num1)
def max1():
a = num1[0]
for i in num1:
if i > a:
a = i
return a
print(max1())
import random
def sz(n):
a = 0
for i in range(1,n+1):
b = random.randint(1,7)
a += b
return a
print(sz(4))
dict1 = {
'a':1, 'b':2, 'c':3}.items()
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()
def jc(n=10):
for i in range(1,n):
n *= i
return n
print(jc())