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
Write the definition of a method dashedLine, with one parameter, an int. If the parameter is negative or zero, the method does n
ZanzabumX [31]

Answer:

import java.util.Scanner;

public class DashLine {

public static void main(String[] args) {

// Declaring variables

int n;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

// Getting the input entered by the user

System.out.print("Enter a number :");

n = sc.nextInt();

// calling the method by passing the user entered input as argument

dashedLine(n);

}

//This method will print the dashed line for number greater than zer

private static void dashedLine(int n) {

if (n > 0) {

for (int i = 1; i <= n; i++) {

System.out.print("-");

}

System.out.println();

}

}

}

Explanation:

5 0
3 years ago
I / a / caught / when / was / on / disease / holiday / I​
statuscvo [17]

Answer:

Ig it'd be - I caught a disease when i was on a holiday.

4 0
3 years ago
Read 2 more answers
Components of an operating system include process,memory,and file management. what is another component of and operating system
kirza4 [7]

Answer:

Wrong it's actually C.

Explanation:

APEX

4 0
2 years ago
Read 2 more answers
Learning Task 1 Write YES if the statement is correct and NO if it is incorrect.
kipiarov [429]

Answer:

1) YES

2) YES

3) YES

4) NO

5) YES

7 0
3 years ago
Not everything is a success all of the time! So do you know which version of Windows was the least popular?
mario62 [17]

Answer:

windows xp

Explanation:

I think because it is not fast and don't play the games and programs which have higher requirements

7 0
3 years ago
Other questions:
  • PLEASE HELP 15 POINTS Emma plans on building a dog house using an algorithm. What will be the final step of the process? a) crea
    6·1 answer
  • ) Consider a router that interconnects four subnets: Subnet 1, Subnet 2, Subnet 3 and Subnet 4. Suppose all of the interfaces in
    11·1 answer
  • While working a night job at a call center, Eric creates an app called EatOut, which can be used to place orders at restaurants,
    14·1 answer
  • Pinterest, a visual bookmarking Website, logs more than 14 terabytes of new data each day, which means its storage needs are con
    10·1 answer
  • A law office has been leasing dark fiber from a local telecommunications company to connect a remote office to company headquart
    14·1 answer
  • Which of the following best describes a group?
    13·1 answer
  • Assume that passwords are selected from four-character combinations of 26 alphabeticcharacters. Assume that an adversary is able
    11·1 answer
  • Anyone know the answer I need help
    12·1 answer
  • Note that common tasks are listed toward the top, and less common tasks are listed toward the bottom. According to O*NET, what a
    14·1 answer
  • What is the missing part to have the output as 3 2 1 while count &gt;0 : print(count) count -= 1
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!