簡體   English   中英

如何在python中向float(十進制)數字添加一個短語?

[英]how do i add a phrase to a float (decimal) number in python?

所以我正在研究一個代碼來划分數字及其處理if語句和東西。 我現在擁有的是:

num= int(input( "Enter the numerator: "))  

den= int(input( "Enter the denominator: "))   

if (den==0):  
    print ("Error - cannot divide by zero")  
else:  
    print ("Decimal: ") + (num/den)  

好吧,我的問題是最后一行代碼。 我不知道我做錯了什么,我嘗試過float,str和int,每次它都給我一個問題。

代碼的最后一行幾乎沒有語法錯誤。 此外,在連接之前隱藏浮動到字符串,否則它將使用TypeError進行回溯。

num= int(input( "Enter the numerator: "))  

den= int(input( "Enter the denominator: "))   

if (den==0):  
    print ("Error - cannot divide by zero")  
else:  
    print ("Decimal: " + str(num/den))  # Check syntax. Convert float to string

嘗試這個

來自未來的進口部門

num,den = map(int,raw_input()。split())#enter space space input

如果den == 0:

print "Error - cannot divide by zero" 

其他:

print "Decimal: " + str(num/den)  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM