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
Whats the next lyric,i baked you a pie,pie,pie
eduard
“oh boy what flavor”
4 0
3 years ago
Read 2 more answers
Which best describes Sayid’s error?
Sonja [21]
<span>Change "move only through matter" to "move through space and matter."</span>
8 0
3 years ago
A a a a I don't need help!?
Arlecino [84]

Answer:

ok

Explanation:

ok

6 0
2 years ago
Write a program that reads a person's first and last names separated by a space, assuming the first and last names are both sing
Dmitriy789 [7]

<em>Complete Question:</em>

<em>Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline.  </em>

<em>Example output if the input is: Maya Jones </em>

<em>Jones, Maya</em>

<em></em>

<em>In C++</em>

<em></em>

Answer:

The program written in C++ is as follows

<em>#include<iostream></em>

<em>using namespace std;</em>

<em>int main(){</em>

<em>string lname, fname;</em>

<em>cout<<"First name: ";</em>

<em>cin>>fname;</em>

<em>cout<<"Last name: ";</em>

<em>cin>>lname;</em>

<em>cout<<lname<<", "<<fname;</em>

<em>return 0;</em>

<em>}</em>

<em />

Explanation:

This line declares lname, fname as string to get the user's last name and first name, respectively

<em>string lname, fname;</em>

This line prompts the user for first name

<em>cout<<"First name: ";</em>

This line gets the user first name

<em>cin>>fname;</em>

This line prompts the user for last name

<em>cout<<"Last name: ";</em>

This line gets the user last name

<em>cin>>lname;</em>

This line prints the desired output

<em>cout<<lname<<", "<<fname;</em>

7 0
3 years ago
Write a 5 sentence paragraph about why charles babbage invented the computer.
Colt1911 [192]

Answer:

The computer was invented in order to automate mathematical calculations that were previously completed by people. Charles Babbage is considered to be the “father” of the computer.

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • On January 1, 1980, Moises deposited $1850 into a savings account paying 5.6% interest, compounded quarterly. If he hasn't made
    9·2 answers
  • How long does it take to wire a house?
    14·2 answers
  • Working together, printer A and printer B would finish the task in 24 minutes. Printer A alone would finish the task in 60 minut
    8·1 answer
  • Your program is going to compare the distinct salaries of two individuals for the last 5 years. If the salary for the two indivi
    15·1 answer
  • 1. ___________ ensures the integrity and security of data that are passing over a network.
    13·1 answer
  • Amazon Web Services and Microsoft Azure are some of the most widely used _______.
    7·1 answer
  • How do i find the greatest common factor of two numbers?
    14·1 answer
  • Need help please asap
    9·1 answer
  • Jonathan is in the process of creating a photo of a fluttering flag with cars moving around in the background. He wants the flag
    13·2 answers
  • Which terms would be found in search for "Mo*”? Check all that apply.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!