Jump to content

I need help with Python.

Jerahmy
Go to solution Solved by Enderman,

just like in regular math you can do a<b or a>b

so if answer>5 then it should return 1

figure the other one out

Hello!

 

I cannot figure how to set this up to come out right. Can anyone help?

 

  1. On line 2, fill in the if statement to check if answer is greater than 5.
  2. On line 4, fill in the elif so that the function outputs -1 if answer is less than 5.

def greater_less_equal_5(answer):
    if ____:
        return 1
    elif ____:          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
 

Thanks,

Jerahmy

Link to comment
Share on other sites

Link to post
Share on other sites

just like in regular math you can do a<b or a>b

so if answer>5 then it should return 1

figure the other one out

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Enderman said:

just like in regular math you can do a<b or a>b

so if answer>5 then it should return 1

figure the other one out

I'm stupid, thank you.

Link to comment
Share on other sites

Link to post
Share on other sites

I dont do Python myself, so I don't know the syntax ... but this is kinda what you want:

//Greater than 5
if (answer > 5)
{
	//Answer is greater than 5, so it should return 1?
	return 1;
}
//Less than 5
if (answer < 5)
{
	//Answer is less than 5, so it should return -1?
	return -1;
}
//The else statement you have which will only get triggered if the answer is 5
else
{
	return 0;
}

I kinda made this in a Javascript/C# kinda way so you gotta translate it into Python syntax yourself

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×