亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python 小目標8

Python day 14

  1. Who is the True Lucky Guy?

In Wechat red-packet game, the best luck winner usually ends up in with a negative balance, because he/she has to send out a red-packet after winning the Best Luck Red Packet. That leaves the Second best luck guy to be the true best luck overall in the game.

Suppose we have a  list of input

2 3 6 6 5

We want to pick out 5.

How do we find the second best luck guy?
let’s try to work in python

Solution:

# Second Best Luck Star
    n = int(input())
    arr = list(map(int, input().split()))
    lis=list(arr)[:n]
    lis1=sorted(set(lis))
    length=len(lis1)
    print(lis1[length-2])

# Alternative Solution
    zes = max(arr)
    i=0
    while(i<n):
        if zes ==max(arr):
            arr.remove(max(arr))
        i+=1
print(max(arr))
5

Note: I used a long time to figure out why int() or input() doesnt work on my spyder, it turns out after any line includes int or input, we need to actually input the value before move on to next code time!

[caption id=“attachment_1984” align=“alignnone” width=“550”]

PublicDomainPictures / Pixabay[/caption]

2. Second Lowest grade

We are learning Excel 😱😱😱 this semester, i think this is the biggest joke in the universe. The sad thing is I dont know how to use it, and i dont want to learn. I am still hoping i won’t be the student with the lowest grade in the class. Second lowest it is ok! So i will program with python to find out who has the second lowest grade!

Suppose we have input

Holly
32
Berry
31.2
Tina
31
Amy
40
Hope
39 

Solution

marksheet = []
for _ in range(0,int(input())):
    marksheet.append([input(), float(input())])

def low2(t2):
    #take the second lowest
    t3=(sorted(t2, key=lambda x:(x[1] , x[0])))[1]
    #Pick the Scores
    t4=t3[1]
    return('\n'.join([a for a,b in sorted(marksheet) if b == t4]))
print(sort(marksheet))

# Alternative Solution
second_highest = sorted(list(set([marks for name, marks in marksheet])))[1]
print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest]))

Output:
Berry

Happy Practicing!!! except for Excel! 😡

Reference:

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消