第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在使用多個(gè) if 語(yǔ)句時(shí)存儲(chǔ)數(shù)字?

如何在使用多個(gè) if 語(yǔ)句時(shí)存儲(chǔ)數(shù)字?

弒天下 2022-12-27 14:50:01
您應(yīng)該將可選匹配項(xiàng)移動(dòng)到一個(gè)捕獲組中:import pandas as pddata = """\2930 Beverly Glen Circle Los Angeles435 S. La Cienega Blvd. Los Angeles12224 Ventura Blvd. Studio City9570 Wilshire Blvd. Beverly Hills26025 Pacific Coast Hwy. Malibu""".split('\n')df = pd.DataFrame(data)print(df)cities = ['Los Angeles', 'Studio City', 'Beverly Hills','Malibu']c = '|'.join(cities)pat = fr'(.*?)\s({c})'                     # fixed pattern with f and rdf = df[0].str.extract(pat,expand=True)print(df)輸出:                          0              10  2930 Beverly Glen Circle    Los Angeles1   435 S. La Cienega Blvd.    Los Angeles2       12224 Ventura Blvd.    Studio City3       9570 Wilshire Blvd.  Beverly Hills4  26025 Pacific Coast Hwy.         Malibu分享編輯跟隨于 2020 年 6 月 4 日 1
查看完整描述

1 回答

?
婷婷同學(xué)_

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個(gè)贊

這是固定版本。我建議你再做一些工作:)


from random import choice


t = ["rock", "paper", "scissors"]


tie = 0

lose = 0

win = 0


for i in range(0, 10):

    print("1... 2... 3... go!")


    # you need to refresh these variables on every for iteration

    computer = choice(t)

    player = None


    # if you're using while to make sure player inputs, that's the only thing that needs

    # to be within the while loop

    while not player:

        player = input("rock, paper, scissors: ")

    print("Computer: ", computer)

    print("User: ", player)


    # I would look for a way to simplify determining the winner

    if player == computer:

        # tie += 1 is the same as tie = tie + 1

        tie +=1

        print("Tie!")

    elif player == "rock":

        if computer == "paper":

            lose += 1

            print("You lose!")

        else:

            win += 1

            print("You win!")

    elif player == "paper":

        if computer == "scissors":

            lose += 1

            print("You lose!")

        else:

            win += 1

            print("You win!")

    elif player == "scissors":

        if computer == "rock":

            lose += 1

            print("You lose!")

        else:

            win += 1

            print("You win!")

    else:

        print("That's not a valid play. Check your spelling!")



print("Final Tally")

print("************")

print("User Wins: ", win)

print("Computer Wins: ", lose)

print("Ties: ", tie)


if tie > win and tie > lose:

    print("It's a tie!")

elif win > tie and win > lose:

    print("You won!")

else:

    print("The computer won!")

更新:顯然我無(wú)事可做。好吧,這是一種簡(jiǎn)化獲勝條件的直接方法。


    win_condition_rock = player == 'rock' and computer == 'scissors'

    win_condition_paper = player == 'paper' and computer == 'rock'

    win_condition_scissors = player == 'scissors' and computer == 'paper'


    if player == computer:

        # tie += 1 is the same as tie = tie + 1

        tie +=1

        print("Tie!")


    elif any([win_condition_paper, win_condition_scissors, win_condition_rock]):

        win += 1

        print('You win')


    else:

        lose += 1

        print('You lose')

更新 2:這是對(duì)有效輸入的檢查


    while player not in t:

        player = input("rock, paper, scissors: ").lower()

        if player not in t:

            print('Invalid input')


查看完整回答
反對(duì) 回復(fù) 2022-12-27
  • 1 回答
  • 0 關(guān)注
  • 87 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)