Python-print aus float oder integer

Wie kann ich drucken Sie schwimmt, wenn das Ergebnis dezimal-oder print-out-integer, wenn das Ergebnis keine Dezimalzahl?

c = input("Enter the total cost of purchase: ")
bank = raw_input("Enter the bank of your credit card (DBS, OCBC, etc.): ")
dbs1 = ((c/float(100))*10)
dbs2 = c-dbs1
ocbc1 = ((c/float(100))*15)
ocbc2 = c-ocbc1


if (c > 200):
    if (bank == 'DBS'):
        print('Please pay $'+str(dbs2))
    elif (bank == 'OCBC'):
        print('Please pay $'+str(ocbc2))
    else:
        print('Please pay $'+str(c))
else:
    print('Please pay $'+str(c))

exit = raw_input("Enter to exit")

Beispiel-Ergebnis

Enter the total cost of purchase: 250
Enter the bank of your credit card (DBS, OCBC, etc.): OCBC
Please pay $212.5

Enter the total cost of purchase: 250
Enter the bank of your credit card (DBS, OCBC, etc.): DBS
Please pay $225.0
  • Ich sehe nicht das problem, ich habe es und es funktionierte gut
  • whats up kirin? Baum arbeiten Antwort gepostet worden ist, aber Sie nicht wählen Sie eine von Ihnen!
InformationsquelleAutor Kirin Sim | 2013-05-16
Schreibe einen Kommentar