fbpx

Question #1 Explanation

Click here to view Question #1.

You want to build a program that allows the user to determine how much clout they have based on their follower count. The available options are:

  • (1) Newbie
  • (2) Building the brand
  • (3) Probably a micro-influencer
  • (4) Absolute clout

The program will first ask the user for the number of followers that the user has. It should then determine their clout level based on their follower count. Lastly, it should send the user a message displaying the clout level, like so:

This account's clout level is 'Probably a micro-influencer'.

If the program can't determine what their clout level is for any reason, it'll display an error message.

invalid_input = False # Flag variable checking if the follower_count is a valid number

# Ask the user how many followers the account has
? - Answer A - ?

# If they have 100 or less followers, they're a 'Newbie'
if follower_count >= 0 and follower_count <= 100:
    clout_level = "Newbie"

# If they have between 100 and 1500 followers, they're "Building the brand"
? - Answer B - ?
    clout_level = "Building the brand"

# If they have between 1500 and 5000 followers, they're a micro-influencer
elif follower_count > 1500 and follower_count <= 5000:
    clout_level = "Probably a micro-influencer."

# If they have over 5000 followers, they have absolute clout
elif follower_count > 5000:
    clout_level = "Absolute clout."

# If they don't enter a positive number, change flag variable to true and alert user
? - Answer C - ?
    ? – Answer D - ?
    print("We could not determine the account's clout level. Please enter a valid number.")

# If the input was not invalid, tell the user what the account's clout level is
if invalid_input == False:
    print(? – Answer E - ?)

Answer

Answer A: follower_count = int(input("How many followers does the account have? "))

Answer B: elif follower_count > 100 and follower_count <= 1500:

Answer C: Must purchase Python Cram Kit to see.

Answer D: Must purchase Python Cram Kit to see.

Answer E: Must purchase Python Cram Kit to see.

The full video explanation is locked. To view it, you must purchase Lifetime Access, Python Cram Kit or BUS 104 Cram Kit Bundle. Already purchased? Click here to log in.

Answer A Explanation

Read the comment above "? - Answer A - ?" in the program itself. It states...

...
# Ask the user how many followers the account has
? - Answer A - ?
...

In this part of our Python program, we're asking the user a question, one that answers how many followers the account they're looking at has.

Let's first start by defining the variable that this follower count will be saved as. To do this, we must first look through the program and see if it's already defined. Do that now.

If you looked hard enough, you might've seen the following variable, follower_count, written down a few lines.

...
# If they have 100 or less followers, they're a 'Newbie'
if follower_count >= 0 and follower_count <= 100:
    clout_level = "Newbie"
...

Using this context, we're able to determine that the variable in our Answer A should be follower_count.

Answer A: follower_count =

Now, we must determine how we'll get the value of follower_count. In the comment above "? - Answer A - ?", it stated that we must ask the user how many followers the account has. How do we ask a question with Python? With an input statement! We'll use the "Input statement" Code Template to start us out.

Answer A: follower_count = input(question)

What's our question going to be? One that asks the user how many followers the account has. It doesn't really matter how you word this.

Answer A: follower_count = input("How many followers does the account have? ")

One last step before we move on... this value must be an integer, not a string. Strings are automatically returned by input statements. So, how will we save it as so?

By placing "int()" around our input statement! This will convert the return value of our input statement into an integer, rather than it's automatic class of a string. We can reference the "Input statement variations... with integers" Code Template to help us write this.

Answer A: follower_count = int(input("How many followers does the account have? "))

Answer B Explanation

To determine what we should place in Answer B, we must look above and below it. Above "? - Answer B - ?", we have an if statement...

...
# If they have 100 or less followers, they're a 'Newbie'
if follower_count >= 0 and follower_count <= 100:
    clout_level = "Newbie"
...

...and below it, we have an else if statement.

...
# If they have between 1500 and 5000 followers, they're a micro-influencer
elif follower_count > 1500 and follower_count <= 5000:
    clout_level = "Probably a micro-influencer."
...

This gives us the huge hint that Answer B must be an else if statement! Why so? Because no other conditional statement can go between an "if" and an "else if" statement. Remember...

If statements always come first.
Else if statements must go between if statements and else statements.
Else statements always are at the end.

Therefore, Answer B will start with an else if statement. We'll use the "Else if statements" Code Template to start us out.

Answer B: elif condition:

So, what's the condition going to be? Let's view the comment above "? - Answer B -?".

...
# If they have between 100 and 1500 followers, they're building the brand
? - Answer B - ?
    clout_level = "Building the brand"
...

Since we're dealing with the "followers" of the account, we know we'll be using the follower_count variable. How can we state that it's between 100 and 1500 though?

First, let's start with the 100 part. We've already covered accounts that have less than or equal to 100 followers in the if statement before "? - Answer B - ?". So, for this part we want to cover all accounts that have greater than 100 followers. Therefore, the value of follower_count must be greater than or equal to 101.

Answer B: elif follower_count > 100:

Now for the 1500. We want to cover all accounts that have above 100 followers and less than or equal to 1500 followers. We'll first use the "and" logical operator to combine these two conditions...

Answer B: elif follower_count > 100 and ...:

...and then we'll include this second condition, that the follower_count is less than or equal to 1500.

Answer B: elif follower_count > 100 and follower_count <= 1500:

PAID CONTENT

This is the end of the preview. To unlock the rest, get the Lifetime Access, Python Cram Kit or BUS 104 Cram Kit Bundle.

Already purchased? Click here to log in.

Leave a Comment