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

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

您如何比較2個(gè)變量與不同類型的數(shù)據(jù)?

您如何比較2個(gè)變量與不同類型的數(shù)據(jù)?

慕工程0101907 2021-04-08 04:21:34
比較兩個(gè)名為target的變量,并使用Python 3猜測(cè)一個(gè)是整數(shù),一個(gè)是字符串。import randomimport systarget = random.randint(1, 20)name = input ('Hello, what is your name?')print ('Hello, %s. I am thinking of a number from 1 to 20. You will have 3 tries, and after each try, I will tell you if the number that I am thinking of is lower or higher. Try to guess it!' % name) guess = input ('What number do you think I am thinking of?')if guess == target:    print ('Congratulations! You won! Please play again!')    sys.exit()else:    print ('You did not guess the number correctly.')    if target < guess:        print ('The number that I am thinking of is smaller than your guess. Try again')    else:        print ('The number that I am thinking of is larger than your guess. Try again!')
查看完整描述

1 回答

?
慕后森

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

您可以通過(guò)以下方式簡(jiǎn)單地將輸入從字符串解析為整數(shù):

guess = int(input('What number do you think I am thinking of?'))

然后,您可以將其自由地與所需的任何整數(shù)進(jìn)行比較。


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

添加回答

舉報(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)