I have to write a program that prompts user for input and should print True only if every character in string entered by the user is either a digit ('0' - '9') or one of the first six letters in the alphabet ('A' - 'F'). Otherwise the program should print False.
I can't use regex for this question as it is not taught yet, i wanted to use basic boolean operations . This is the code I have so far, but it also outputs ABCH as true because of Or's. I am stuck
string = input("Please enter your string: ")
output = string.isdigit() or ('A' in string or 'B' or string or 'C' in string or 'D' in string or 'E' in string or 'F' in string)
print(output)
Also i am not sure if my program should treat lowercase letters and uppercase letters as different, also does string here means one word or a sentence?
stringis the entire object. You should loop over each element in string likefor char in string:and then perform your logic.