I need help with this python exercise:Verify User:

The final listing for remember_me.py assumes either that the user has already entered their username or that the program is running for the first time. We should modify it in case the current user is not the person who last used the program.

Before printing a welcome back message in greet_user(), ask the user if this is the correct username. If it’s not, call get_new_username() to get the correct username.

Also, use a check_username() function to prevent any nested if statements from occurring in greet_user()

Answers

Answer 1
Answer:

No prob. Let's go over the Python code,

Here's your complete Python program with the added function `check_username()`:

```

import json

filename = 'username.json'

def get_stored_username():

   try:

       with open(filename, 'r') as f:

           username = json.load(f)

   except FileNotFoundError:

       return None

   else:

       return username

def get_new_username():

   username = input("What's your username? ")

   with open(filename, 'w') as f:

       json.dump(username, f)

   return username

def check_username():

   username = get_stored_username()

   if username:

       correct = input(f"Are you {username}? (y/n) ")

       if correct.lower() == 'y':

           return username

   return get_new_username()

def greet_user():

   username = check_username()

   print(f"Welcome back, {username}!")

greet_user()

```

Remember to call `greet_user()` to start the whole shebang. Let me know if anything needs clearing up!


Related Questions

A database program helps to ____________.a. Organize, send, and retrieve e-mails quicklyb. Deliver elegant presentations to a large audience easilyc. Create professional documents with an intuitive WYSIWYG interfaced. Organize, store, and retrieve large amounts of information easily
One of the problems with Internet voting is:a. there are too many candidates c. potential for voter fraud b. there are too many elections d. everyone doesn't own a computer
Find and enter the correct amount. 5 9 of a $18 restaurant bill = $
It is most important to ask questions when looking at media messages because doing soa. provides a higher level of entertainment value. b. helps you to prepare for a career in media. c. enables you to be an intelligent consumer. d. allows you to determine a product's quality.
Which of the following statements comparing debit cards to credit cards is TRUE?

Given a scanner reference variable named input that has been associated with an input source consisting of a sequence of strings and two int variables, count and longest, write the code necessary to examine all the strings in the input source and determine how long the longest string (or strings are). that value should be assigned to longest; the number of strings that are of that length should be assigned to count.

Answers

Answer:

int count = 0;  //int variables

int longest =0;  // int variables

Scanner input = new Scanner(System.in); // given input is reference variable

String str= new String();  // creating object of sting class

while (input.hasNext()) // taking the input by using scanner reference

{

str= input.next();  // taking input in string

if (str.length() == longest) // checking condition

++count;  // increment the count

else

if (Str.length() > longest) // if string is greater then longest

{

longest = str.length(); // calculating length

count = 1;  // assign count to 1

}

}

Explanation:

Following are the description of the code :

  • Declared a two variable count and longest of  int type.
  • Create a object of String class i.e 'str".
  • Taking input in the string by using scanner reference i.e "input".
  • Finally checking the condition of if and else block and calculating the length of string and assign into longest variable.

The code that examines all the strings in the input source and determines how long the longest string (or strings are) is the following:

total = 0;% initial value is zero, in every while loop it will be incremented

while(input.hasNextInt()){

total += input.nextInt( );

}

Which of the following would increase Aggregate Demand?A. Decrease in Inflation
B. Increase in Income
C. Increase in Interest Rates

Answers

increase in income,I guess

Which of the following options would you use when saving a document with a new filename? *

Answers

I would say save as I beleieve
Save As, or Save A Copy.

Whats in a computer?

Answers

A lot of things are in a computer there a motherboard, A cpu, A hard drive etc. A motherboard is the computer system  bascilly its the heart for a computer. The cpu is the the brain of a computer it controls on your computer and keeps it going good. finally a hard rive is the memory of your computer it stores all the data including files, photos, etc
CPU/processor,Motherboard, and Power supply unit.

Which of the following expressions will produce a valid random integer between the int values m and n inclusive, where m < n?

Answers

Answer:

The solution code is written in Python:

m = 1

n = 5

d = random.randint(m, n)

Explanation:

To get a random integer between m and n inclusive, we can make use of Python randint method. It will take two parameters, m and n. By giving two integers as an input (e.g. 1 and 5) to randint, it will generate a random integer between 1 to 5 inclusive.

How many spaces are required between punctuation? 1.One 2.Two 3.Three

Answers

Answer: One Space

Explanation: