大数据分析及应用 – 实验_2022春

Python基础 – 控制结构

1

break

2

for i in inputlist.split(','):
    student=studentname[count]

3

for score in subjectscore:

4

List = iter(List)

Python基础 – 文件操作与异常处理

1

with open('src/Step1/test.txt') as file_object:
    lines = file_object.readlines()
    i=0
    for line in lines:
        print(line.rstrip())
        i=i+1
        if i==n:
            break

2

with open('src/Step2/test2.txt','w') as example:
    example.write(s)

3

except:
    print("We can't take a root by minus")
else:
    print(answer)

Python基础 – 函数结构

1

def plus(numbers):
   add=0
   for i in numbers:
      add+=i
   return add
d=plus(numbers)

2

def gcd(a,b):
    if a<b:
        t=a
        a=b
        b=t
    while b:
        maxs=a%b
        a=b
        b=maxs
    return a

3

def _gcd(a,b):
    if a < b:
        t=a
        a=b
        b=t
    while b:
        t = a%b
        a = b
        b = t
    return a
 
def lcm(a,b):
    return int(a*b/_gcd(a,b))

Python基础 – 函数调用

1

def prime(n):
    if n <= 1:
        return("False")
    else:
        for i in range(2,n):
            if n % i == 0:
                return("False")
                break
        return("True")

2

def func_call(numbers):
    for i in range(len(numbers) - 1):
        for j in range(len(numbers) - i - 1):
            if numbers[j] > numbers[j + 1]:
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]
    return numbers

func_call(numbers)    
print(numbers)

3

def circle(n):
    return PI * n* n

s = circle(n)
print('%.2f' %s)

Python基础 – 列表

1

a=guests.pop()
guests.insert(2,a)
guests.pop(1)
print(a)
print(guests)

2

source_list.sort()
print(source_list)

3

data_list = list(range(lower,upper,step))
l=-(-(upper-lower)//step)
print(l)
min_value = min(data_list)
max_value = max(data_list)
s=max_value-min_value
print(s)

4

a=my_menu[::3]
print(a)
b=my_menu[-3::]
print(b)

Python基础 – 元组与字典

1

print(tuple(menu_list))
print(max(menu_list))

2

menu_dict['lamb']=50
print(menu_dict['fish'])
menu_dict['fish']=100
del menu_dict['noodles']
print (menu_dict)

3

for key in menu_dict.keys():
    print(''+key)
for value in menu_dict.values():
    print(value)

4

menu2= {}
menu2['fish']=menu1['fish']*2
menu2['pork']=menu1['pork']*2
 
menu_total.append(menu2)
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!