Ich versuche die Operation zu drucken, aber die erste Anweisung funktioniert, aber die zweite Anweisung hat einen Fehler.nicht unterstützter Operandentyp "float" und "str"
conSwitch = raw_input("Enter cycle of context switch: ")
cycleOpr = raw_input("Enter cycle operation: ")
totalCycle = float(conSwitch) + float(cycleOpr) + float(conSwitch)
print "Context =", conSwitch
print "Cycle operation =", cycleOpr
print "Context switch back =", conSwitch
print("\n")
print (conSwitch + " + " + cycleOpr + " + " + conSwitch)
print ("Total number of cycle is: " + format(totalCycle))
print("===================================================")
reqSecond = raw_input("Enter cycle request second:")
print "Total cycle request =", totalCycle
print "Cycle request per second =", reqSecond
print("\n")
totalSpent = float(totalCycle) * float(reqSecond)
print (totalCycle + " * " + reqSecond)
print ("Total number of spent = " + format(totalSpent))
=========================================== ===================
First statement
Work===>> print (conSwitch + " + " + cycleOpr + " + " + conSwitch)
Second statement
Error===>> print (totalCycle + " * " + reqSecond)
print ("Gesamtzahl abgebrannter = {0}". format (totalSpent)) oder "Gesamtzyklus-Anfrage = {0}". format (totalCycle) –
Ich denke, das liegt daran, dass Sie versuchen, einen Float mit einer Zeichenkette zu verketten. Probieren Sie "print (str (totalCycle) +" * "+ str (reqSecond))" aus – LismUK