2014-03-04 59 views
-3

請讓我知道,如何以及在何處插入繼續在我的Python的計算器程序語句... 這是我的計劃請讓我知道,如何以及在何處插入繼續在我的Python的計算器程序語句

print "Welcome to maths calculator" 
a=input("\n Enter the first number :") 
b=input("\n Enter the second number :") 
ch=raw_input("\nEnter the operatoions you want from following... "\ 
      "\nAddition (+)" \ 
      "\nSubtraction (-)" \ 
      "\nMultiplication (*)" \ 
      "\nDivision (/)" \ 
      "\nPress any sign u want....: ") 
if ch == '+': 
     print "The addition result is :", a+b 
elif ch=='-': 
     print "The subtraction result is :", a-b 
elif ch=='*': 
     print "The multiplication result is :",a*b 
elif ch=='/': 
     print "The division result is :",a/b 
else: 
     print "\nPlease choose correct one.... " 

結果是

歡迎數學計算器

輸入第一個數字:12

輸入第二個數字:10

從以下內容輸入你想要的operatoions ...
加(+)減 ( - ) 乘法(*) 司(/) 按任意ü希望的跡象。 ...: - 減的結果是:2

>

我在這裏需要什麼? 我想繼續工作,當一個執行完成後, 請給

+0

'continue'是使用的語句在'for'和'while'循環中。你的程序不包含循環。所以答案是,瞭解循環並使用它們 - 一個無限的'while True'循環在這裏可以很好地工作,並帶有一個包含'break'語句的退出選項。所有這些都在官方的Python教程和其他數百個免費提供的資源中介紹。 – l4mpi

回答

1

把你的整個代碼的方法,然後你可以使用這樣的事情,

while True: 
    again = input("Again? Yes/No: ").lower() 
     if again == "yes": 
      //call your method here 
     elif again == "no": 
      sys.exit(0) 
+0

在Python中,'true'是'True',並且圍繞它的括號完全是不必要的。 – l4mpi

+0

我需要在這裏調用哪個方法?你能簡單解釋一下嗎? – Jothimani

+0

感謝修正@ l4mpi。我對語法感到困惑......發生在你學習多種編程語言時! :D –

相關問題