2017-03-07 2 views
-5

ちょっと、リトライの答えが「はい」の場合、このコードセクションのループを作成するのに助けが必要です。私はPythonにはとても新しいので、インターネットは今まで役に立っていないようです。乾杯!このコードセクションのループを作成したい

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

インターネットでは、「python loop」 –

答えて

1

すべてのメインコードを次のように機能に移動します。

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)") 
関連する問題