-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram5B2.py
More file actions
23 lines (22 loc) · 825 Bytes
/
Program5B2.py
File metadata and controls
23 lines (22 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Program5B2
# Matthew Ancelin
# this program will create a dictionary from a file
f = open("Lab5B2.txt", 'r')
fcontent = f.read()
data = fcontent.split()
reservedWords = tuple(data)
print (reservedWords)
wordCheck = input("Enter a variable name to check if its valid: ")
for i in range(len(wordCheck)):
if wordCheck[0].isnumeric():
print ("Cant have a number as first character in variable name")
break
elif wordCheck[i].isalpha() or wordCheck[i].isnumeric() or wordCheck[i] == "_":
print ("letter ", i, " good")
else:
print ("the character ", wordCheck[i], " is invalid for use in variable name")
break
if wordCheck in reservedWords:
print (wordCheck, " is a reserved word and is invalid as a variable name")
else:
print (wordCheck, " is a valid variable name")