print( validate_age("20") ) # True
print( validate_age("20.5") ) # False
print( validate_age("20a") ) # False
print( validate_age("300") ) # False
print( check_eligibility(20) ) # True
print( check_eligibility(15) ) # False
Module 4 Assignments
Short Project 03
Due date: Sep 24, Tuesday at 7pm
Short Programming projects are submitted during our weekly 45-minute in-person lab sessions. Each lab sessions is guided by two TAs. The instructions for the short project will be available only during the lab sessions. To schedule your lab session go to the weekly lab session spreadsheet.
Programming Problems
Programming Problems should be submitted to gradescope.
Programming Problem 7
Due date: Sep 24, Tuesday at 7pm
Write a program to check whether a person is eligible for voting or not.
Your program should validate the input from the user (although you don’t have to ask for the input, in other words, no need to call input()). So you should write two functions: validate_age
and check_eligibility
.
One of the functions does the following:
- Its name is
validate_age
- It takes a
string
argument, calledage
- It checks if
age
is valid by checking that: it contains only 0 to 9 digits (in other words, it determines ifage
can be transformed to an integer), and that the integer is between 0 and 110 (inclusive). - It returns
True
ifage
is a valid integer, andFalse
otherwise
The second function does the following:
- Its name is
check_eligibility
- It takes an integer argument, called
age
- If the age is greater or equal to 18, return
True
, otherwise returnFalse
Name the program eligible.py
. Make sure that gradescope gives you the points for passing the test cases.
Development test cases:
You can also download the ready-to-run script to test your solution.
Programming Problem 8
Due date: Sep 24, Tuesday at 7pm
Write a function that does the following:
- Its name is
max3
. - It has 3 parameters,
x
,y
andz
. - It returns the greatest value of the three.
- Do not use any built-in functions like max.
Name the program max_of_three.py
. Make sure that gradescope gives you the points for passing the test cases.
Development test cases:
print( max3(1, 1, 1) ) # 1
print( max3(1, 2, 1) ) # 2
print( max3(-1, -1, 0) ) # 0
print( max3(100, 0, 0) ) # 100
print( max3(19, 19, 0) ) # 19
print( max3(2, 0, 2) ) # 2
print( max3(-100, 0, 0) ) # 0
You can also download the ready-to-run script to test your solution.