2016-09-14 22 views
-6

私はプログラミングクラスに少しのコードを書いており、デスクを作るコストを計算するプログラムを作る必要があります。 DrawerAmountを文字列ではなく整数に変更する手助けが必要です。文字列を整数に変換するには?

def Drawers(): 
print("How many drawers are there?") 
DrawerAmount = input(int) 
print("Okay, I accept that the total amount of drawers is " + DrawerAmount + ".") 
return DrawerAmount 

def Desk(): 
    print("What type of wood is your desk?") 
    DeskType = input() 
    print("Alright, your desk is made of " + DeskType + ".") 
    return DeskType 

def Calculation(DrawerAmount, DeskType): 
    if "m" in DeskType: 
     FinalPrice = DrawerAmount * 30 + 180 
    elif "o" in DeskType: 
     FinalPrice = DrawerAmount * 30 + 140 
    elif "p" in DeskType: 
     FinalPrice = DrawerAmount * 30 + 100 

def Total(): 
    print("The final price is " + FinalPrice) 

DrawerAmount = Drawers() 
DeskType = Desk() 
Calculation(DrawerAmount, DeskType) 
FinalPrice = Total() 
+3

int型(DrawerAmount) – MooingRawr

+0

あなたのインデントは – depperm

+2

を離れてあなたのコードでも動作していている、 '' DrawerAmount =入力(int)をご確認ください? –

答えて

0

I need help changing my DrawerAmount to an integer, not a string!

これを試してみてください:

v = int(DrawerAmount) 
0
def Drawers(): 
    draweramount = input("How many drawers are there?") 
    print("Okay, I accept that the total amount of drawers is " + draweramount +  ".") 
    return int(draweramount) 

def Desk(): 
    desktype = input("What type of wood is your desk?") 
    print("Alright, your desk is made of " + desktype + ".") 
    return desktype 

def Calculation(draweramount, desktype): 
    if "m" in desktype: 
     finalprice = draweramount * 30 + 180 
    elif "o" in desktype: 
     finalprice = draweramount * 30 + 140 
    elif "p" in desktype: 
     finalprice = draweramount * 30 + 100 
    return finalprice 

draweramount = Drawers() 
desktype = Desk() 
finalprice=Calculation(draweramount, desktype) 
print("The final price is ",Calculation(draweramount,desktype)) 

You haven't specified the output in case the input is not "P" or "M" or "O". Have your functions in small letters and include _ whenever its a combination of two or more words eg. function_name()

関連する問題