1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
myrzilka [38]
3 years ago
6

write a function that takes a string as parameter, return true if it’s a valid variable name, false otherwise. You can use keywo

rd module’s iskeyword() to determine if a string is keyword.
Computers and Technology
1 answer:
never [62]3 years ago
8 0

Answer:

The solution code is written in Python 3:

  1. import keyword  
  2. def checkValidVariable(string):
  3.    if(not keyword.iskeyword(string)):
  4.        return True  
  5.    else:
  6.        return False  
  7. print(checkValidVariable("ABC"))
  8. print(checkValidVariable("assert"))

Explanation:

Firstly, we need to import keyword module so that we can use its iskeyword method to check if a string is registered as Python keyword (Line 1).

Next, we create a function checkValidVariable that takes one input string (Line 3). Within the function body, we use iskeyword method to check if the input string is keyword. Please note the "not" operator is used here. So, if iskeyword return True, the True value will be turned to False by the "not" operator or vice versa (Line 4-5).

We test the function by passing two input string (Line 9-10) and we shall get the sample output as follows:

True

False

You might be interested in
In Excel you insert a comment in a worksheet by using the ____ tab on the Ribbon.
White raven [17]
Review
(I was suprised too)
3 0
4 years ago
Cell phone producers charge a _____, which consumers pay to buy the phones. profit production cost price
alex41 [277]
The answer is price i have gone over this specific lesson multiple times.
4 0
3 years ago
You run the ipconfig command on your computer, and it reports an IP address of 169.254.75.10 on the Ethernet interface. Which de
Ray Of Light [21]

Answer:

This IP address is assigned to the interface by the following device:

d. The local computer

Explanation:

  • Ipconfig command is also known as Internet protocol configuration command. It is command line tool that is used to configure the IP of network connections. This command give us information about the information about IP and other parameters like default gateways.
  • The IP address 169.254.X.X is such IP address that can have values from 169.254.0.1 to 169.254.254.
  • 169.254.X.X is a Automatic Private IP Address that tells that our computer is not connected with the internet because the computer is not getting IP address from server.
5 0
4 years ago
How to use a function in Python?
dolphi86 [110]

Answer:

The four steps to defining a function in Python are the following:

Use the keyword def to declare the function and follow this up with the function name.

Add parameters to the function: they should be within the parentheses of the function. ...

Add statements that the functions should execute.

4 0
3 years ago
How would you convert this base 10 decimal into a base 2number?:
Tju [1.3M]

Answer:

The method of converting a base 10 or decimal number into base 2 or binary number is as following:-

  1. Divide the decimal number by 2 and store it's remainder.
  2. keep dividing the decimal number by 2 until it becomes 0 and also keep storing it's remainder.
  3. Then write the remainders in reverse order.This the binary number.

Refer the attached image for better explanation.

6 0
4 years ago
Other questions:
  • Your friend wants to know about Microsoft Expression Web 4. Which of the following terms will you use to describe Microsoft Expr
    5·1 answer
  • to create a cover letter to send to a potential employers along with a resume what software program should you use
    10·1 answer
  • D. The 7-bit ASCII code for the character '&' is:
    7·1 answer
  • Using the find and replace tool would be most appropriate when
    6·2 answers
  • The algorithm ____ is used to find the elements in one range of elements that do not appear in another range of elements.
    5·1 answer
  • How to jailbreak ios 9.2 ? Is there anyway???!!!!
    12·1 answer
  • What is microsoft certification?
    8·1 answer
  • Write the count below the rests. <br><br> How do I do I do this?<br> Help guys
    7·1 answer
  • And tags are examples of stand - alone tags.
    15·1 answer
  • When can design templates be applied to the presentation?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!