0

I'm new here so please be understanding, also I'm not a native speaker so sorry for my English.

I’m writing the code and I need a solution which checks what user’s entered. I show You my code.

Input can't be the string because a,b and c are the coefficients of function

Could You help me?

while True:
    a1 = input("(podaj wartość współczynika ax^2) a = ")
    try: 
        a1 = int(a1) or a1 = float(a1)
        break
    except ValueError:
        print("Wpisałeś jakiś dziwny znak, nie postąpiłaś/eś zgodnie z instrukcją")

while True:
    b2 = input("(podaj wartość współczynika bx) b = ")
    try: 
        b2 = int(a1) or b2 = float(a1)
        break
    except ValueError:
        print("Wpisałeś jakiś dziwny znak, nie postąpiłaś/eś zgodnie z instrukcją")

while True:
    c3 = input("(podaj wartość współczynika c) c = ")
    try: 
        c3 = int(a1) or c3 = float(a1)
        break
    except ValueError:
        print("Wpisałeś jakiś dziwny znak, nie postąpiłaś/eś zgodnie z instrukcją")

os.system("pause")
Velocibadgery
  • 3,670
  • 2
  • 12
  • 17
  • 1
    It looks like you're assigning `b2 = int(a1)` instead of `b2 = int(b2)`. Same for c3, and for the float conversions. – Dillon Nov 05 '21 at 18:57
  • If I were you, I would write a function to do this. Pass in your prompt, and return a float. – Tim Roberts Nov 05 '21 at 19:01
  • By the way, the statement `a1 = int(a1) or a1 = float(a1)` is nonsense and will cause a syntax error. I'm not sure what you were trying to do there. Which one do you want? – Tim Roberts Nov 05 '21 at 19:02
  • 2
    See [here](https://stackoverflow.com/q/379906/6273251) for how to read in user input as either an into or a string. And [here](https://stackoverflow.com/q/23294658/6273251) is how to keep prompting the user for input until they've entered something valid. – Random Davis Nov 05 '21 at 19:06

0 Answers0