0

Current Code:

def character_a():

    character_a = input('Enter First Dot or Dash (. / -): ')

character_a()

if not character_a == "." or "-":
    print('Invalid Character.. Try Again')
    character_a()

else:
    print('Valid Character')

Hello Im trying to write a python script where it asks you for a input of either a "." or "-" only problem is that you can in theory do any other letter or number. And I got it to check if its a character like a,b,c,etc But not Numbers How Can i make sure they only do "-", ".". And for my future code how can I also check to make sure they either do "-", ".", or "0" And not some other random character/digit like ; or ] etc etc.

Jelloies
  • 1
  • 1
  • 1
    `if not character_a in ['.', '-', '0']:` – Rashid 'Lee' Ibrahim Jan 12 '23 at 21:45
  • Note that your `character_a` variable only exists within your function, which returns nothing; so it won't exist after the function call. Or rather it will exist (it's the name of your function), but will never be equal to '.', '-' or any character. – Swifty Jan 12 '23 at 21:46
  • You need to `return` your variable from the function, and then you need to assign it to something, e.g. `first_char=character_a(); if not first_char in ['.', '-', '0']:...` – G. Anderson Jan 12 '23 at 21:47
  • Also see [How to ask a user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – G. Anderson Jan 12 '23 at 21:49

0 Answers0