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

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

制作一個(gè)更精確的程序來(lái)計(jì)算(例如 2/3),而不僅僅是 16 個(gè)字符

制作一個(gè)更精確的程序來(lái)計(jì)算(例如 2/3),而不僅僅是 16 個(gè)字符

縹緲止盈 2021-10-10 10:58:43
這是我的代碼:def start():    #main input variable to get a sign to do    calculator = input('What would you like to calculate? (x, /, +, -): ')    #gets 2 #'s to multiply, add, subtract, or divide     if (calculator) == ('+'):        add = input('what is the frist number would you like to add? ')        addi = input('what is the second number would you like to add? ')    elif (calculator) ==('-'):        sub = input('what is the first number would you like to subtract? ')        subt = input('what is the second number you would like to subtract? ')    elif (calculator) == ('/'):        div = input('what is the first number would you like to divide? ')        divi = input('what is the second number would you like to divide? ')    elif (calculator) == ('x'):        mult = input('what is the first number would you like to multiply? ')        multi = input('what is the second number would you like to multiply? ')    #failsafe if done incorrect    elif (calculator) != ('x', '/', '-', '+'):        print('try again')        return    #adds 2 inputted #'s    if calculator == '+' :        sumAdd = float (add) + float (addi)        print(sumAdd)    #multiplies the 2 inputted #'s    elif calculator == 'x' :        sumMul =  float (mult) * float (multi)        print(sumMul)    #divides the 2 inputted #'s    elif calculator == '/' :        sumDiv = float (div) / float (divi)        print(sumDiv)    #subtracting the 2 inputted #'s    elif calculator == '-' :        sumSub = float (sub) - float (subt)        print(sumSub)    #returns to top of code to do another setup    returnstart()這很簡(jiǎn)單,我明白了??梢苑祷?cái)?shù)字/整數(shù),但我是從頭開(kāi)始做的,我很滿意只是想知道如何在不做更多代碼的情況下獲得 16 位以上的小數(shù)。還要看看是否有比例如 (float) 或 (int) 更好的價(jià)值來(lái)完成這項(xiàng)工作。如果不是一切都很好,如果您有任何答案,請(qǐng)打開(kāi)謝謝!
查看完整描述

2 回答

?
海綿寶寶撒

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

試試這個(gè)decimal模塊:


from decimal import Decimal, getcontext


# set desired precision, 30 for example

getcontext().prec = 30


# normal

print(1 / 7)

# 0.14285714285714285


# with Decimal

print(Decimal(1) / Decimal(7))

# 0.142857142857142857142857142857


查看完整回答
反對(duì) 回復(fù) 2021-10-10
?
四季花海

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

評(píng)論是正確的,format()是不準(zhǔn)確的。


您可以使用十進(jìn)制模塊。


from decimal import *

getcontext().prec = 6 #set the number of decimals you prefer

Decimal(1) / Decimal(7)

>>> Decimal('0.142857')

getcontext().prec = 28

Decimal(1) / Decimal(7)

>>> Decimal('0.1428571428571428571428571429')


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

添加回答

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