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

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

如何修復(fù)文本計(jì)算器中的錯(cuò)誤?

如何修復(fù)文本計(jì)算器中的錯(cuò)誤?

慕桂英546537 2022-07-05 17:35:56
我試圖制作一個(gè)非常簡(jiǎn)單的文本計(jì)算器,但我一直遇到這個(gè)問題。這是我的代碼:num1 = input("Enter in the first number")num2 = input("Enter in the second number")sign = input("Enter in the calculator operator you would like")elif sign = "+":   print(num1 + num2)elif sign = "-":   print(num1 - num2)elif sign = "*":   print(num1*num2)elif sign = "/":   print(num1/num2)抱歉,我是 python 新手...
查看完整描述

3 回答

?
MMTTMM

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

您的代碼不起作用的原因是因?yàn)槟皇菍蓚€(gè)數(shù)字相乘/除/加/減,而這兩個(gè)數(shù)字現(xiàn)在聲明為一個(gè)字符串。


在 python 中,您不能將字符串作為整數(shù)進(jìn)行加/減/乘/除。您需要將 num1 和 num2 聲明為整數(shù)。


num1 = int(input("Enter in your first number"))

num2 = int(input("Enter in your second number"))

sign = input("Enter in the calculator operator you would like")


if sign == "+":

   print(num1 + num2)

elif sign == "-":

   print(num1 - num2)

elif sign == "*":

   print(num1*num2)

elif sign =="/":

   print(num1/num2)


查看完整回答
反對(duì) 回復(fù) 2022-07-05
?
偶然的你

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

您的代碼中有很多語法錯(cuò)誤,請(qǐng)查看注釋以了解可以改進(jìn)的地方,底部有一些閱讀材料!


num1 = int(input("Enter in the first number")) # You need to cast your input to a int, input stores strings.

num2 = int(input("Enter in the second number")) # Same as above, cast as INT

sign = input("Enter in the calculator operator you would like")


# You cannot use `elif` before declaring an `if` statement. Use if first!


if sign == "+": # = will not work, you need to use the == operator to compare values

   print(num1 + num2)

elif sign == "-": # = will not work, you need to use the == operator to compare values

   print(num1 - num2)

elif sign == "*": # = will not work, you need to use the == operator to compare values

   print(num1*num2)

elif sign == "/": # = will not work, you need to use the == operator to compare values

   print(num1/num2)

代碼可以很好地適應(yīng)這些更改,但是您應(yīng)該閱讀Python 語法和運(yùn)算符!


查看完整回答
反對(duì) 回復(fù) 2022-07-05
?
大話西游666

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

您收到此錯(cuò)誤是因?yàn)槟J(rèn)情況下輸入會(huì)給出一個(gè)字符串。在使用它之前,您必須將其轉(zhuǎn)換為 int。


num1 = int(input("Enter in the first number"))

num2 = int(input("Enter in the second number"))

sign = input("Enter in the calculator operator you would like")


if sign == "+":

   print(num1 + num2)

elif sign == "-":

   print(num1 - num2)

elif sign == "*":

   print(num1*num2)

elif sign == "/":

   print(num1/num2)


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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