Question: Please help on this Python question! In Python, there are three main rules for naming variables. The first character cannot be a number. Only letters,
Please help on this Python question!
In Python, there are three main rules for naming variables.
The first character cannot be a number.
Only letters, numbers, and the underscore character are allowed.
Python keywords are reserved and cannot be used as variable names.*
Write a program that prompts users to enter a potential variable name and tells them whether or not it is valid. Your program should consist of two functions. The first should take one argumentthe potential variable name, validate the name, and return Boolean True if it is valid or False if it is not. The second, a main() function, should get input from the user, call the validator function and print This is a valid variable name or This is not a valid variable name.
*Pythons keyword module can be used to test if a string is a keyword or not.
import keyword keyword.iskeyword("elif") # True Here is a demo of the program.
Enter your Python variable name: high_temp This is a valid variable name.
Here is another demo.
Enter your Python variable name: highTemp2 This is a valid variable name.
And another.
Enter your Python variable name: 2_high_temp This is not a valid variable name.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
