-1

hi i want to end the code if a letter is typed in Cost1 but im not sure how to do that i want it to be only a number in there. any help is appreciated.( the .isletter is just filler for an example)

Item1 = input("What item do you want to buy? ") # asking what item is
if Item1.isdigit():
  exit("ERROR")

Cost1 = input("How much does this item cost? ") # asking cost of item
if Cost1.isletter():
  exit("ERROR")
keeyoow
  • 17
  • 1
  • This code will "end" no matter what you enter for Cost1. – Scott Hunter May 11 '22 at 13:01
  • @ScottHunter what makes you think so? – matszwecja May 11 '22 at 13:04
  • Welcome to Stack Overflow. Please read [ask] and, in the future, try to [find solutions yourself](https://meta.stackoverflow.com/questions/261592). To find the linked duplicate, I tried using `[python] string is letter` in the site search. Trying something [similar in a search engine](https://duckduckgo.com/?q=python+string+is+letter) also works very well. – Karl Knechtel May 11 '22 at 13:05
  • 1
    "what makes you think so?" The fact that there is no more code to run afterwards, I imagine. – Karl Knechtel May 11 '22 at 13:05
  • That said, no matter what the user types, the result will be **a string**, and **not** a number. I added another duplicate about the overall problem that you seem to want to solve. – Karl Knechtel May 11 '22 at 13:08

1 Answers1

-3
from string import ascii_lowercase
if 'a' in ascii_lowercase:
    print("letter")
matszwecja
  • 6,357
  • 2
  • 10
  • 17