Computer Science Worksheet Page 3

ADVERTISEMENT

Wednesday 20th Jan 2016
name = input(“What name?”)
if name == ‘cathal’:
print(“Yabado”)
else:
print(“Yabadont”)
Other conditions can be catered for. For example, we could extend the code above to print
“Yabajo” if the name ‘joe’ is entered. It would look like the following:
name = input(“What name?”)
if name == ‘cathal’:
print(“Yabado”)
elif name == ‘joe’:
print (“Yabajo”)
else:
print(“Yabadont”)
The if statement (and elif) can be much more complex. But this is enough for today’s exercises.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 3