try:/except: returns a syntax error in Python when trying to run module

hbss

Below is my code and the error is on line 4 "except" gives a syntax error... (this is a debugging and error catching assignment. I don't see what is wrong with it)

while True:
        try:
                userInputOne = input(int("How much time in hours a week, do you spend practicing? ")
        except TypeError:
                print("Oops! Practice time must be rounded to the nearest integer. It also needs to be a numerical value! ")
                break
    else:
        userInputTwo = str(input"How good to do want to be? Enter 'very good', 'good', mediocre, 'not good' ")
        if userInputTwo not in ('very good', 'good', 'mediocre', 'not good'):
            print("Please use one of the options. ")
        else:
            print("Let's calculate...")
            break
Eirik Fesker

I Attached the working code. Syntax Error was caused by missing parethesis and wrong indents. Take a look at your else: statement. It's not at the same height as the try: statement. TypeError means, that you dont have to convert your input to strings, because they already are. Otherwise i suggest you create some variables and convert them via int() when you want to calculate with them.

while True:
    try:
        userInputOne = input("How much time in hours a week, do you spend practicing? ")
    except TypeError:
        print("Oops! Practice time must be rounded to the nearest integer. It also needs to be a numerical value! ")
        break
    else:
        userInputTwo = input("How good to do want to be? Enter 'very good', 'good', mediocre, 'not good' ")
        if userInputTwo not in ('very good', 'good', 'mediocre', 'not good'):
            print("Please use one of the options. ")
        else:
            print("Let's calculate...")
            break

Edit: I recommend using PyCharm (if you don't) with its Auto-Indent function and nice "indent guidelines". So you can see many mistakes much easier.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Trying to run Python using Reticulate giving a module not found error, but it is installed

Try/except when using Python requests module

"ImportError: No module named" when trying to run Python script

Python `no module pip.__main__;` error when trying to install a module

try except syntax error

Python try / except keep trying until no errors

Syntax error when try to launch zeppelin, spark with python in ubuntu

Syntax error on const {LEVEL,MESSAGES} when trying to run meteor application

Why do I get a syntax error when trying to run a fab module?

Syntax error when trying to define series of numeric variables in python

Python Selenium - Invalid syntax error with try except

SQL syntax error when try insert into by python

"Module not found error" when trying to run pytube on PyCharm

Try and except returns error, however when run without, no error occurs?

Python eval() syntax error when trying to evaluate an expression

try except statement error python

Confusing error when trying to run Python script

Syntax error in when trying to run a tornado main.py

Python Syntax Error (except ValueError:)

Syntax error when trying to create new empty list in Python

Syntax error when trying to import Cntlr from arelle module

Syntax error when trying to run an IF EXISTS query

Python try except finally invalid syntax error

When I try to run my application of submition data in SQLite there is an error 1 syntax error

Is there a way to get rid of the syntax error when I run try and except?

How to still show error message when using try and except in Python

terra package returns error when try to run parallel operations

Pinia gives module error in terminal when trying to run dev

What is `except*` syntax in Python? (TryStar in ast module)