【解決方法】While ループ電卓

[ad_1]

Hi! I'm new to programming and I need help with my phyton code for a calculator. Here's what the calculator needs to do:
 
- Every time the function runs, it takes three inputs: first number, the operation (either of +, -, * or /). 
If the operation is anything other than the above-given ones, a suitable message shows up 
The result of the operation is displayed at the end.
- *** The calculator should keep running unless interrupted by Ctrl-C. 
- *** The function should never crash. Include exception handling at suitable locations to avoid falling into any errors (exceptions).

 - ***The file you submit should have the function call to this function too.
What I marked with *** is what I'm having the most trouble with.

This is the calculator running:
<pre>
Python

>>>計算()
23
K
90
不明な操作

私が試したこと:

Here's what I have so far: 
>>>def calc():
    a = int(input())
    b = input()
    c = int(input())
    while True:
        try:
            if b== "+" :
                print(a+c)
                break
            elif b == "-":
                print(a - c)
                break
            elif b == "*":
                print(a*c)
                break
            elif b == "https://www.codeproject.com/":
                print(a / c)
                break
            else:
                print("Unknown Operation")
                break

解決策 1

移動 input ループ内のステートメント …

解決策 2

let lowerLimit : Int = 1
let upperLimit : Int = 3

[ad_2]

コメント

タイトルとURLをコピーしました