PYTHON: Trying to calculate the period it takes for a pendulum to swing on different planets, I'm extremely new at this so there may be an easy solution:
def main(): print('Period of a pendulum') Earth_gravity = 9.8 Mars_gravity = 3.7263 Jupiter_gravity = 23.12 print(' ') pen = float(input('How long is the pendulum (m)? ')) if pen < 0: print('illegal length, length set to 1') else: print(' ') main() What I want to do is if the value entered is negative for it to be set to "1" and display the message "illegal length, length set to 1" . If it is a positive number then I'll have it do the equation to find out the period of a pendulum swing. I am getting the syntax error message of " if pen < 0: builtins.NameError: name 'pen' is not defined" Thank you!
ifandelseneed to be indented like the rest of the function body.penis a local variable.