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

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

涉及到函數(shù)if elif的問題,請問該怎么解決?

涉及到函數(shù)if elif的問題,請問該怎么解決?

繁華開滿天機(jī) 2022-05-24 10:06:04
1 def count(temp1,cha,temp2):2 res = int(temp1) cha int(temp2)3 return res4 way = input("請輸入計(jì)算方式(加/減/乘/除):")5 temp1 = input("輸入第一個(gè)數(shù)")6 temp2 = input("輸入第二個(gè)數(shù)")7 if way == '加':8 res = jia(temp1,+,temp2)9 elif way == '減':10 res = jian(temp1,-,temp2)11 elif way == '乘':12 res = cheng(temp1,*,temp2)13 elif way == '除':14 res = chu(temp1,/,temp2)15 print(res)下面的這個(gè)補(bǔ)充的和上面的是一樣的,但最初提問或許系統(tǒng)有些問題,沒有縮進(jìn)————————————————————————————————————1 def count(temp1,cha,temp2):2 res = int(temp1) cha int(temp2)3 return res4 way = input("請輸入計(jì)算方式(加/減/乘/除):")5 temp1 = input("輸入第一個(gè)數(shù)")6 temp2 = input("輸入第二個(gè)數(shù)")7 if way == '加':8 res = jia(temp1,+,temp2)9 elif way == '減':10 res = jian(temp1,-,temp2)11 elif way == '乘':12 res = cheng(temp1,*,temp2)13 elif way == '除':14 res = chu(temp1,/,temp2)15 print(res)
查看完整描述

1 回答

?
RISEBY

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

不是很明白你給的代碼邏輯。你定義了一個(gè)函數(shù),叫count,傳入的是三個(gè)參數(shù),要做的是將三個(gè)參數(shù)拼接成一個(gè)算式并返回。但是在后面的代碼中出現(xiàn)了“jia”、“jian”、“cheng”、“chu”四個(gè)函數(shù)名,你都沒定義怎么調(diào)用?


#coding:gbkdef count(temp1,cha,temp2):    if isinstance(temp1,(int,float)) and isinstance(temp2,(int,float)):        res = str(temp1) + cha + str(temp2)    else:        res = temp1 + cha + temp2    return resway = input("請輸入計(jì)算式(加/減/乘/除):")temp1 = input("輸入第數(shù)")temp2 = input("輸入第二數(shù)") if way == '加':    res = count(temp1,'+',temp2)elif way == '減':    res = count(temp1,'-',temp2)elif way == '乘':    res = count(temp1,'*',temp2)elif way == '除':    res = count(temp1,'/',temp2)print(res)


查看完整回答
反對 回復(fù) 2022-05-30
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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