Ece 262 Lecture
Ece 262 Lecture
1. Printing in Python:
Examples: print the following
❖ My father’s house is big. I’m proud of it
❖ * * *
*
*
2. Python Strings:
Examples:
❖ greet = ‘Hello, Class’. Print characters from position 1 to 4. Print characters from
position 7 to the end making sure the printed characters are all capital letters.
❖ a=’Hello’, b = ‘Class’. Print the word to appear as: Hello, Class.
Print the word to appear as: Hello my Classmates.
❖ a = 4, b= 272. Print: I have 4 gallons of water in room 272.
4. Functions:
Examples:
❖ write a function that can calculate the area of rectangle.
❖ Write a function that checks if a number is an even or odd number. It should print
‘even’ if the number is even, otherwise it should print ‘odd’.
PRACTICE QUESTIONS
A. Write a program that allows a user to enter his/her age to check his/her eligibility to vote.
Print ‘Eligible, kindly cast your vote’ if entered age is greater than 18, otherwise print
‘Ineligible, please come back when you are 18’.
B. Write a program that accepts input from user. Print True if entered value is divisible by 5,
otherwise print False.
C. Write a program that accepts two inputs from a user. Print the greater number or print ‘The
numbers are equal’. E.g if entered value is 4 and 7, print 7. If entered number is 8 and 8,
print ‘‘The numbers are equal’’.
D. Write a program that accepts an input from a user. Print ‘Even number’ if entered value is
even or print ‘Odd number’ if entered value is odd. You must make sure the entered value
is a number. If the entered value is not a number, print ‘Enter a valid number’.
E. Coca Cola recently announced a discount of 10% if a customer buys Coke worth more than
1000 Naira. If one coke costs 200 Naira. Write a program that allows the customer enter
the quantity of coke he/she wants to buy. Then calculate and print the amount the customer
is expected to pay. E.g if a customer wants to buy 7 cokes, print ‘1260 Naira’.
F. In UNN regulation, a student will not be allowed to sit for an examination if his/her
attendance is less than 75%.