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

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

Python 中的簡(jiǎn)單代碼中不使用逗號(hào)的“SyntaxError:無(wú)效語(yǔ)法”背后的原因

Python 中的簡(jiǎn)單代碼中不使用逗號(hào)的“SyntaxError:無(wú)效語(yǔ)法”背后的原因

繁星coding 2023-09-05 20:26:14
運(yùn)行此代碼時(shí),我收到 SyntaxError:無(wú)效語(yǔ)法:total = int(input("compra total: "))if total  > 700000: totald = total - total*0.2elif total > 300000: totald = total - total*0.15elif total > 150000: totald = total -total*0.10else: totald = total*1print("Centro Comercial Unale?o\n" "Compra Más y Gasta Menos\n" "NIT: 899.999.063\n" "Total:$"+str(int(totald)) "En esta compra tu descuento fue $"+str(int(total-totald)))我意識(shí)到錯(cuò)誤不是在這里放置逗號(hào)或求和符號(hào):......"Total: $"+str(int**(totald)), "\nEn** esta compra tu descuento fue $"+str(int(total-totald)))但我不明白必須放置這兩個(gè)選項(xiàng)中任何一個(gè)的原因。為什么我不能像其他字符串一樣放置一個(gè)空格,這兩個(gè)符號(hào)的目的是什么?謝謝您的幫助??!
查看完整描述

3 回答

?
慕容708150

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

total = int(input("compra total: "))


if total  > 700000: totald = total - total*0.2

elif total > 300000: totald = total - total*0.15

elif total > 150000: totald = total -total*0.10

else: totald = total*1


print("Centro Comercial Unale?o\n" "Compra Más y Gasta Menos\n" "NIT: 899.999.063\n" "Total:$"+str(int(totald)) + "En esta compra tu descuento fue $"+str(int(total-totald)))

當(dāng)您在 print 語(yǔ)句中連接字符串時(shí),您遺漏了一個(gè) + 。


查看完整回答
反對(duì) 回復(fù) 2023-09-05
?
肥皂起泡泡

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

因?yàn)槟蕾囉谧址淖执?lián)來(lái)獲取由字符串分隔的文字。

這僅適用于字符串文字。編譯器無(wú)法將字符串連接到由空格分隔的任意表達(dá)式,只能連接到文字。

>>> "foo" "bar"

'foobar'

>>> 'foo' frobnicate()

? File "<stdin>", line 1

? ? 'foo' frobnicate()

? ? ? ? ? ? ? ? ? ?^

SyntaxError: invalid syntax

這發(fā)生在編譯時(shí),


>>> import dis

>>> dis.dis("'foo' 'bar'")

? 1? ? ? ? ? ?0 LOAD_CONST? ? ? ? ? ? ? ?0 ('foobar')

? ? ? ? ? ? ? 2 RETURN_VALUE

所以它不能依賴運(yùn)行時(shí)結(jié)果。


逗號(hào)之所以有效,是因?yàn)樗皇浅蔀?的另一個(gè)參數(shù)print。


例如


>>> print('hello')

hello

>>> print('hello', 'world')

hello world


查看完整回答
反對(duì) 回復(fù) 2023-09-05
?
qq_花開花謝_0

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

我建議像這樣設(shè)置文本格式:

print("Centro Comercial Unale?o\r\nCompra Más y Gasta Menos\r\nNIT: 899.999.063\r\nTotal:${} En esta compra tu descuento fue ${}".format(totald, totald))


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

添加回答

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