-1
所以我有一個程序,我想要得到的提示,使用兩個參數。我首先提示用戶輸入一個用戶賬單,這是賬單費用的金額,然後我提示用戶輸入15%或30%的提示,但讓他們輸入十進制格式。我的問題是,當我調用Problem3()方法後,在獲取userBill和tipRate的值之後,它也調用了problem3中的方法提示,但是我不斷收到此錯誤。對困惑感到抱歉。Python雙參數不起作用
>>> def Problem3():
userBill = input("Enter the total of your bill at the restaurant.")
tipRate = input("Would you like to tip .15 or .30 of your bill?")
userBill = int(userBill)
tipRate = float(tipRate)
def Tip(userBill, tipRate):
tipRate1 = .15
tipRate2 = .30
userTip = 0
if tipRate == tipRate1:
userTip = tipRate1 * userBill
else:
userTip = tipRate2 * userBill
print("Your tip is " + userTip + " since you've want to tip at")
Tip(userBill, tipRate)
>>> Problem3()
Enter the total of your bill at the restaurant.100
Would you like to tip .15 or .30 of your bill?.15
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
Problem3()
File "<pyshell#22>", line 16, in Problem3
Tip(userBill, tipRate)
File "<pyshell#22>", line 15, in Tip
print("Your tip is " + userTip + " since you've want to tip at")
TypeError: Can't convert 'float' object to str implicitly
>>>
喔我認爲我知道這個問題,也許是因爲我沒有調用方法,但哈哈......讓我試試看看它是否可行 –
使用'str(userTip)'。 – Zety