Tuesday, September 30, 2008

Show Me Boobs Of Indian Heroines

7) Begin: if statement, elif and else

Education allows us to check if a condition is met if the condition continues else and otherwise processing a different block. Here is an example which is better:

  
# / usr / bin / python

name = raw_input ( What's your name? )
if name == " plaoo " : # check if name and 'equal to "plaoo"
print " Bravooo " # if the condition and' respected print to video "Bravooo"
else : # If the condition is not met
print "Your name is " + name # print to video "Your name is" + the string variable name

As you can see there are spaces after else if and this is called indentation. In python E ' you can use 4 spaces required or (as I do io) un TAB . Se usate TAB ricordatevi che l'istruzione non sarà eseguita . Con i 4 spazi, invece, restituisce l'errore se l'identazione è sbagliata.

Spieghiamo meglio, if nome == "plaoo" : se nome è uguale (==) a "plaoo" se è così allora stampa "bravooo"
else altrimenti stampa "ti chiami" + il valore di nome.
L'istruzione if ha bisogno di operatori di confronto come == nell' esempio precedente e questi sono quelli uttilizzati:
  
< minore di
> maggiore di
==
equal to or less <=
> = \u200b\u200bgreater than or equal to
! =
other


another example with variables Numeric:
  
# / usr / bin / python
numero_magico = 8
number = input ( Pick a number from 0 to 10: )
if numero_magico == number :
print "Congratulations you have guessed the number "
elif number > numero_magico :
print "Too high "
elif number < numero_magico :
print "Too low "


What's happening? After creating the variable numero_magico user is prompted to choose a number if numero_magico ( if numero_magico ) is equal (== ) to number Press a video "Complimenti hai indovinato il numero" ( print "Complimenti hai indovinato il numero" )
altrimenti se numero ( elif numero )è maggiore ( > ) di numero_magico stampa a video "Troppo alto" ( print "Troppo alto" )
altrimenti se numero( elif numero ) è troppo basso ( < ) di numero_magico stampa a video "Troppo basso" ( print "Troppo basso" ). Possiamo usare tutti gli elif che vogliamo per avere il controllo delle variabili.
elif viene usato come if , cioè può fare un confronto con le condizioni else instead is used when none of the comparisons with the conditions.

* * TO REMEMBER: Use
indentation which would be spaces after if, elif and else.
All statements must end with ":"

0 comments:

Post a Comment