#๐Ÿ”’ In need of help figuring this out

23 messages ยท Page 1 of 1 (latest)

blazing wedge
#

I have an assignment for loops and before I can do that, I need to familiarize myself with booleans and expressions in order to do loops. I don't think programming is for me but I can't really afford to fail this class and I need to pass this semester. Here is my question for this practice quiz:

lethal stratusBOT
#

@blazing wedge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

blazing wedge
#

Goal: Learn to use control flows to obtain conditional results.

Assignment: Assume the variable x has been assigned a float. Write code that assigns the absolute value of x to the variable value without using the built-in abs function.

Note: The absolute value of a number is the number without the sign. For example:

if x is -3, your code will assign 3 to value
if x = 99, your code will assign 99 to value
brisk mulch
#

Do you know how to write an if statement?

blazing wedge
#

It's a lot to remember but is it if x > y ?

brisk mulch
#

That's not a complete statement. Let's start with this: goto you book, notes, whatever and find a complete example of an if / else statement and paste it here

#

Then we'll modify it to do what you want

blazing wedge
#

if sales > 50000:
โ€‰ bonus = 500.0
โ€‰ commission_rate = 0.12
โ€‰ print('You met your sales quota!')

#

this is from the Python textbook

brisk mulch
#

Great. So, what does absolute value mean?

#

(Let's think of what the condition is)

blazing wedge
#

Is it the final number?

brisk mulch
#

absolute value is a math term. Are you not familiar with what it means?

blazing wedge
#

it's been a minute and I don't remember

brisk mulch
#

Ah. Absolute value means: if it's negative, make it positive

#

So, absolute value of -10 is 10

#

Absolute value of 10 is also 10

blazing wedge
#

would it be vice-versa or does it always make the numbers into positives

brisk mulch
#

Always positive

blazing wedge
#

ok

brisk mulch
#

They say that 'x' is a float (a number), and you need to make 'value' equal to the absolute value of x

lethal stratusBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.