2016-11-11 3 views
0

Ich bin ziemlich neu zu Python und so fragte ich mich, ob jemand mir helfen könnte, herauszufinden, meine While-Schleife und Break-Anweisungen.When und Break-Anweisungen für Python 2.7

Ich kann es entweder weiter oder brechen, aber nie beides.

Ich habe das Thema recherchiert und festgestellt, dass alle Beispiele, die ich finde, für Zahlen und so weiter sind oder dass die gelieferten Informationen einfach nicht für mich klicken.

So jede Hilfe wäre willkommen.

Dieses Programm dient zur Berechnung Ihrer Wochenlöhne.

während True:

Hours_Worked = int(raw_input("How many hours have you worked this week?:\n"))#This line of code allows the user to input the amount of hours they have worked in whole numbers only. 


Hourly_Rate = float(raw_input("What is your hourly rate?:\n" u"\u00A3"))#This line of code allows the user to input their hourly rate of pay in floating numbers to wither a whole or decimal points. 


Tax = int(raw_input("What is your current Tax rate?:\n" u"\u0025"))#This line of code allows the user to input their tax rate. 


Nat = int(raw_input("What is your National Insurance rate?:\n" u"\u0025"))#This line of code allows the user to input their National Insurance rate. 


Total_Weekly_Pay = (Hours_Worked*Hourly_Rate)#This line of code works out the weekly pay before deductions. 


Total_Weekly_Pay_After_Deductions = Total_Weekly_Pay - (Tax*Total_Weekly_Pay/100) - (Nat*Total_Weekly_Pay/100)# This line of code works out the weekly pay after deductions. The Tax and National Insurance rate are worked out by multiplying and then dividing. 


print "Your Total weekly pay before deductions is\n" u"\u00A3%5.2f" %(Total_Weekly_Pay)#This line of code prints out the weekly pay before deductions to the floating points of 5.2. 


print "Your Total weekly pay after Tax and National Insurance deductions is\n" u"\u00A3%5.2f" %(Total_Weekly_Pay_After_Deductions)#This line of code prints out the weekly pay after deductions to the floating points of 5.2. 

cont = raw_input("Would you like to try again? (yes/no)\n") 
if cont == "no": 
    print "Goodbye" 
    break 
+4

'raw_input' einen String zurückgibt , nicht ein 'Wahres'/'Falsches'. –

+0

Auch was ist los mit Ihren leeren Druckanweisungen? –

+0

immer wenn ich "\ n" am Ende einer Eingabezeile hinzufüge, würde es aufhören zu arbeiten, also ging ich mit dem leeren Druck, um es für den Moment weniger überladen zu machen. –

Antwort

1

brechen, wenn es sein sollte:

if cont == "": 

Oder ein Wert sagen Sie den Benutzer zur Ausfahrt, so:

cont = raw_input("Would you like to try again? (Yes/No") 
if cont == "No": 
+1

könnte erklären wollen, was raw_input zurückgibt und warum der Vergleich verschiedener Objekte nicht funktioniert – MooingRawr

+1

ok iv versucht Ihren Vorschlag und schaffte es, es zu arbeiten, auch die leeren Druckoptionen und so weiter. –

+0

@MooingRawr hatte dies in einem Edit getan aber Verbindung verloren: S Darren, im Grunde raw_input gibt eine Zeichenfolge, die auch wenn leer ist noch vorhanden. – Mixone