2017-03-07 5 views
-5

Hey Ich brauche Hilfe beim Erstellen einer Schleife für diesen Abschnitt des Codes, wenn ihre Antwort auf Wiederholen Ja ist. Ich bin sehr neu in Python und das Internet scheint bisher nicht zu helfen. Prost!Möchten Sie eine Schleife für diesen Abschnitt des Codes erstellen

print("Lets try an example!") 
time.sleep(2) 
input("Lets convert 9/2 into a mixed fraction! (Press Enter)") 
input("First we divide 9 by 2. This will give us 4 as the whole number and there will be 1/2 left over! (Press Enter)") 
print("when we put these two numbers in the correct format we get 4 and 1/2") 
print("Press Enter to continue") 
print("-------------------------------------------------------------------------------------------------------------------------------------------------") 
input("Next you are going to complete this conversion! (Press Enter)") 
divide = input("If we have the fraction 19/6, first we must divide the numerator by the denominator. Which number are we dividing by? ") 
if divide == "6": 
    print("Correct! We divide 19 by 6. This gives us 3 as our whole number and 1/6 remainder left over!") 
    time.sleep(1) 
    Fraction_part = input("What is the fraction part of this mixed fraction?") 
    if Fraction_part == "1/6": 
    print("Correct! This means our mixed fraction will be 3 and 1/6") 
    else: 
    print("Incorrect! 1/6 is our answer because we have 1/6 remiander") 
else: 
    print("Incorrect! 6 is the correct answer as it is the denominator in this fraction") 
    time.sleep(1) 
    Fraction_part = input("What is the fraction part of this mixed fraction?") 
    if Fraction_part == "1/6": 
    print("Correct! This means our mixed fraction will be 3 and 1/6") 
    else: 
    print("Incorrect! 1/6 is our answer because we have 1/6 remiander") 
retry = input("Again? (yes/no)") 
+1

Internet hilft, wenn Sie google "Python loop" –

Antwort

1

Versetzen Sie Ihren gesamten Hauptcode in eine Funktion wie im folgenden Beispiel.

def doSomeThing(): 
     print("Lets try an example!") 
     ..... 
     print("Incorrect! 1/6 is our answer because we have 1/6 remiander") 
doSomeThing() 
retry = input("Again? (yes/no)") 
while(retry == "yes"): 
    doSomeThing() 
    retry = input("Again? (yes/no)") 
Verwandte Themen