Python Week 2 All GrPA Solutions
Python Week 2 All GrPA Solutions
GrPA 1
x1 = input()
x2 = input()
y1 = input()
y2 = input()
y3 = input()
z = input()
print(x1)
print(x2)
print(y1)
print(y2)
print(y3)
print(a)
GrPA 2
GrPA 3
# part 1 - If pattern
word = "glow" # str
continuous_tense = True # bool
# part 2
age = 5 # int
is_member = True # bool
# part 3
color_code = "R" # str: valid values are R-red, G-green and B-blue
# <eoi>
# part 1 - basic if
# age_group:str should be "Adult" or "Child" based on the age. assume age greater than or
equal to 18 is adult.
if age >= 18:
age_group = "Adult"
else:
age_group = "Child"
# applicant_type:str should be age goup with the member status like "Adult Member" or "Child
Non-member"
if is_member:
applicant_type = f"{age_group} Member"
else:
applicant_type = f"{age_group} Non-member"
# write the whole if else block
# based on the value of `color_code` assign the `color` value in lower case and "black" if
`color_code` is none of R, B and G
if color_code == "R":
color = "red"
elif color_code == "G":
color = "green"
elif color_code == "B":
color = "blue"
else:
color = "black"
# time_in_hrs:int should have the time in 24 hrs format . Try to do this in a single expression
time_in_hrs = (hour % 12) + (12 if period == "PM" else 0)
# time_of_day:str should have the time of the day as Morning, etc.. use "Invalid" if not withing
the acceptable range
if not is_time_valid:
time_of_day = "Invalid"
else:
if period == "AM":
if 6 <= hour < 12:
time_of_day = "Morning"
else:
time_of_day = "Night"
elif period == "PM":
if hour == 12 or (1 <= hour < 6):
time_of_day = "Afternoon"
else:
time_of_day = "Evening"
GrPA 4
import math
# Multi-purpose application functions
def odd_num_check(number: int) -> str:
return "yes" if number % 2 != 0 else "no"
if operation == "odd_num_check":
number = int(input())
print(odd_num_check(number))
else:
print("Invalid Operation")
if __name__ == "__main__":
main()
GrPA 5
main_dish = input()
time_of_day = int(input())
has_voucher = input().strip().lower() == "true"
is_card_payment = input().strip().lower() == "true"
if has_voucher:
total_cost *= 0.9 # Apply voucher discount
print(f"{total_cost:.2f}")