Gå til innhold

[Python] Hjelp med If, Else og Elif?


Anbefalte innlegg

Skrevet

Hei, jeg er en nybegynner innen Python, og driver på med web-tutorials, og lurer på hvorfor denne koden ikke funker:

#Write your two "if" statements below!
def true_function():
   if 1 + 1 == 2	    #Fill in your `if` statement here!
    return  True	  #Make sure this function returns `True`
def false_function():
   if 1 + 1 != 2		 #Fill in your `if` statement here!
    return   False	 #Make sure this function returns `False`

Kan noen værsåsnill å hjelpe meg og forklare framgangen?

 

Dette er infoen om oppgaven:

 

Let's get some practice in with if statements. Remember, the syntax looks like this:
if expression:
   block line one
   block line two
   et cetera
Write two if statements in the editor: one that returns True, and a second that returns False. Use any expressions you like! (Don't worry about the lines starting with def just yet—we'll cover those in the next unit.)

Videoannonse
Annonse
Skrevet
def true_function():
   if 1 + 1 == 2: 		
	    return True
def false_function():
   if 1 + 1 != 2: 			  
	    return False

print true_function()
print false_function()

Skrevet (endret)

def true_function():
if 1 + 1 == 2: 		
		return True
def false_function():
if 1 + 1 != 2: 			  
		return False

print true_function()
print false_function()

 

>>> print true_function()

True

>>> print false_function()

None

 

Klarer du (eller helst, trådstarter) å se hvorfor? :D

Endret av Terrasque

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...