0% found this document useful (0 votes)
7 views

Week06 - Conditional II

The document provides instructions for 5 programming tasks. Each task involves writing a function to solve a specific problem: 1) determine lottery prizes, 2) issue speeding warnings, 3) translate BMI scores, 4) calculate days in a month, and 5) determine zodiac signs. The tasks require validating inputs, using conditional logic and returning the appropriate output as specified. Students are instructed to follow submission guidelines, include comments and pseudocode, and upload their source code files to the designated grader website.

Uploaded by

9v86tbjgx5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Week06 - Conditional II

The document provides instructions for 5 programming tasks. Each task involves writing a function to solve a specific problem: 1) determine lottery prizes, 2) issue speeding warnings, 3) translate BMI scores, 4) calculate days in a month, and 5) determine zodiac signs. The tasks require validating inputs, using conditional logic and returning the appropriate output as specified. Students are instructed to follow submission guidelines, include comments and pseudocode, and upload their source code files to the designated grader website.

Uploaded by

9v86tbjgx5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

204101 Section 701-703 1/6

Week 06 Condition II

Specification
In the requirement that states [Attachment], please download the Template file
from the Grader and submit only the file(s) that have the specified names for each
respective task.

1. (w06_1_xxxxxxxxx.py) ticket_drawing[Attachment]: Write a function named


ticket_drawing that takes 1 parameter: num and determines the prize and
return prize in string (as shown in example) based on the following conditions:
 If the number is between 45 and 55 (inclusive), the function should return
"First prize".
 If the number is between 15 and 30 (inclusive) or between 75 and 90
(inclusive), the function should return "Second prize".
 For any other number, the function should return "No prize".
 The input number will always be within the range of 1 to 99.

NOTE: delete "pass" keyword before edit the function in template file
Input Output
50 First prize
25 Second prize
70 No prize
90 Second prize
204101 Section 701-703 2/6

2. (w06_2_xxxxxxxxx.py) speed_warning[Attachment]: Create a function named


speed_warning that takes 2 parameters: density and speed. The function to
issue warnings for a car based on the current traffic conditions. The program will
monitor the car density of the traffic (measured in cars per kilometer, denoted as
carDensity) and the speed of the vehicle (measured in kilometers per hour,
denoted as speed).
a. If the traffic is not heavily congested (density is less than or equal to 5
cars/km), it is safe to drive the car at speeds up to 90 km/hr. If the speed
exceeds this limit, a warning should be issued.
b. However, if the traffic is congested (density is greater than 5 cars/km), the
car can only be driven at speeds up to 60 km/hr safely. If the speed
exceeds this limit, a warning should be given.
c. The function should return a Boolean value according to warning status,
True for the situation that a warning should be issued and False for the
safety situation.

NOTE: delete "pass" keyword before edit the function in template file

Input Output
car_density = 4
False
car_speed = 80
car_density = 7
True
car_speed = 70
car_density = 4
True
car_speed = 100
car_density = 7
False
car_speed = 60
204101 Section 701-703 3/6

3. (w06_3_xxxxxxxxx.py) bmi_translate [Attachment] Create a function called


bmi_translation that takes the calculated BMI (Body Mass Index) as input and
returns the corresponding translation based on the BMI range. The function
should have the following specifications:
Function Name: bmi_translation
Parameters: bmi (float) - The calculated BMI value
Return: translation (string) - The translation of the BMI based on the range

Translate the BMI into the following categories:


o If the BMI is less than 18.5, return "Underweight".
o If the BMI is between 18.5 and 24.9 (inclusive), return "Normal weight".
o If the BMI is between 25.0 and 29.9 (inclusive), return "Overweight".
o If the BMI is 30.0 or greater, return "Obese".

NOTE: delete "pass" keyword before edit the function in template file

Input Output
Input weight in kilograms: 55 BMI: 24.444444444444443
Input height in centimeters: 150 Transation of BMI: Normal weight
Input weight in kilograms: 45 BMI: 18.49112426035503
Input height in centimeters: 156 Transation of BMI: Underweight
Input weight in kilograms: 80 BMI: 24.968009737523797
Input height in centimeters: 179 Transation of BMI: Obese
204101 Section 701-703 4/6

4. (w03_4_xxxxxxxxx.py) days_in_month [Attachment] function called


days_in_month that takes 2 integer parameters: month and year. The function
should evaluate and returns an integer representing the number of days in that
specific month and year.
February (month number 2):
o If the given year is a leap year (determined using the is_leap_year
function), February has 29 days.
o If the given year is not a leap year, February has 28 days.
April, June, September, and November (month number 4, 6, 9, 11):
o These months always have 30 days.
All other months (January, March, May, July, August, October, December):
o These months have 31 days.

The function should consider leap years using the is_leap_year function.

NOTE: delete "pass" keyword before edit the function in template file

Input Output
month = 2
29
year = 2020
month = 4
30
year = 2021
month = 12
31
year = 2022
204101 Section 701-703 5/6

5. (w06_5_xxxxxxxxx.py) Zodiac Sign Determination [Attachment] Write a


function called zodiac that takes two parameters: day and month, representing a
person's birthdate. The function should determine the corresponding zodiac sign
based on the astrological zodiac calendar and return it as a string.

The function should follow these specifications:


o Validate the input to ensure the day value is within the range of 1 to 31
and the month value is within the range of 1 to 12
o Determine the zodiac sign based on the provided birthdate using if-elif-
else statements.
o Match the birthdate with the corresponding zodiac sign based on the
following table:
 January 20 - February 18: Aquarius
 February 19 - March 20: Pisces
 March 21 - April 19: Aries
 April 20 - May 20: Taurus
 May 21 - June 20: Gemini
 June 21 - July 22: Cancer
 July 23 - August 22: Leo
 August 23 - September 22: Virgo
 September 23 - October 22: Libra
 October 23 - November 21: Scorpio
 November 22 - December 21: Sagittarius
 December 22 - January 19: Capricorn
o If the day and month values do not correspond to a valid birthdate,
return the string "Invalid date".
 NOTE: delete "pass" keyword before edit the function in template file

Input Output
day = 29
Invalid date
month = 2
day = 18
Gemini
month = 6
day = 23
Capricorn
month = 12
day = 10
Virgo
month = 9
204101 Section 701-703 6/6

Submission
1. The format and order of input/output messages must follow the example
provided during the program execution.
2. The submitted program file must include comments at the beginning of the file
as specified in the course Canvas instructions.
3. The submitted program file must include pseudocode comments for each step of
the program as specified.
4. Upload the source code file to the designated homework submission website
specified for each task at http://cmu.to/grader204101
5. Check the grader instructions from https://cmu.to/instruction

You might also like