Oct-05-2023, 07:50 PM
Here's a program from an intro book:
Why is this?
Also, when I tried this the first several times, I entered a combination of numbers and letters and got output that was my input--the same combination of numbers and letters. It wasn't one of the strings assigned in the if-elif-else branches. Any idea what happened there?
x = input("Enter some input for identification: ") if x.isalnum(): if x.isalpha(): r = "alphabetical" if x.isnumeric(): r = "numeric" elif x.isspace(): r = "space-based" elif x.isascii(): r = "ASCII text" else: r = "a mystery" print("x is " + r)The program is entered in a single Jupyter Notebook cell. When I run the cell and paste the input 987f4, the output seems to be alphabetical or ASCII depending on the previous run. If the previous run was all letters, then the current run will output "alphabetical." Same goes for "ASCII" [with input being shift + number keys to get symbols like &*%(*^ ) ].
Why is this?
Also, when I tried this the first several times, I entered a combination of numbers and letters and got output that was my input--the same combination of numbers and letters. It wasn't one of the strings assigned in the if-elif-else branches. Any idea what happened there?