a variant of elif exercise | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

a variant of elif exercise

n = int(input('n:')) if n == 5: print("n is 5") elif n == 11: print("n is 11") elif n==7: print("n is 7") else: print('n isn\'t 5, 11 or 7')

12th Apr 2019, 2:41 PM
Rodrigo Lozano
Rodrigo Lozano - avatar
3 Réponses
+ 2
What's your question about this?
12th Apr 2019, 3:23 PM
HonFu
HonFu - avatar
+ 1
In Python, everything that ends with a colon, starts a code block - a row of instructions that belong together. (In other languages, brackets are used for that.) So when you write something like this: if x>1: print("Whatever") stuff = input() box_of_stuff = list(stuff) ... all the indented lines belong to the if and are only executed... well... if. :-) And as soon as you *don't* indent a line after such a block, it means the block has ended and you're back in the outer row of instructions.
12th Apr 2019, 6:19 PM
HonFu
HonFu - avatar
0
I'm new in this programming language so when I tried to implement elif example I had an issue because it was indented. Is there any rule about indentation?
12th Apr 2019, 6:11 PM
Rodrigo Lozano
Rodrigo Lozano - avatar