Posts

Showing posts from June, 2023

Module#6Assignment

Question 1: import sys from datetime import datetime from datetime import time from datetime import date def main(): dt = datetime.now() time_string = dt.strftime("%X") # utc = datetime.utcnow() for line in sys.stdin: data = line.strip().split("\t") if len(data) == 6: _date, _time, store, item, cost, payment = data print(f"{dt}\t{time_string}\t{store}\t{item}\t{cost}\t{payment}") main() The output from the code above took too long to produce and I don't know if it's because of the input volume in sys.stdin. The code seems fine to run but it wasn't able to produce output when I tried to call the function main() Question 2: from datetime import timedelta current_dt = datetime.now() new_dt = current_dt + timedelta(days = 2*365) - timedelta(seconds = 60) new_time_string = new_dt.strftime("%X") print(new_dt) Output: 2025-06-24 17:29:16.615776 Question 3: # Creating a timedelta object...

Module #5 Assignment

  class Point: def __init__ ( self , x , y): self .x = x self .y = y def __str__ ( self ): return f"( { self .x } , { self .y } )" class Rectangle: """ A class to manufacture rectangle objects """ def __init__ ( self , posn , w , h): """ Initialize rectangle at posn, with width w, height h """ self .corner = posn self .width = w self .height = h def __str__ ( self ): return f" { self .corner } , { self .width } , { self .height } " def create_rectangle (x , y , w , h): return Rectangle(Point(x , y) , w , h) def str_rectangle (rect): return str (rect) def shift_rectangle (rect , dx , dy): mx = rect.corner.x my = rect.corner.y rect.corner.x = dx + mx rect.corner.y = dy + my def offset_rectangle (rect , dx , dy): mx = rect.corner.x my = rect.corner.y return create_rectangle(mx + dx , my + dy ...

Module #4 Assignment

Problem 1: Roots from math import sqrt a = 1 b = - 5.86 c = 8.5408 print ( f"The quadratic equation is { a } *x^2 { b } *x + { c } " ) x1 = (-b + sqrt(b** 2 - 4 *a*c))/( 2 *a) x2 = (-b - sqrt(b** 2 - 4 *a*c))/( 2 *a) print ( "The square root of the quadratic equation is:" , x1 , x2) The quadratic equation is 1*x^2 -5.86*x + 8.5408 The square root of the quadratic equation is: 3.1400000000000006 2.7199999999999998 Problem 2: Reciprocals decimal_list = [ 1 / 2 , 1 / 3 , 1 / 4 , 1 / 5 , 1 / 6 , 1 / 7 , 1 / 8 , 1 / 9 , 1 / 10 ] for number in decimal_list: print () print ( round ( float (number) , 2 )) 0.5 0.33 0.25 0.2 0.17 0.14 0.12 0.11 0.1

Module #3 Assignment

# 1.Function that takes in person name, and print out greeting name_list = [ "Jake Smith" , "Jonas Bourbon" , "James McGrill" ] def greeting (full): print ( f"Hello { full } !" ) for names in name_list:     greeting(names)   Hello Jake Smith! Hello Jonas Bourbon! Hello James McGrill! # Full Names def greeting_firstlast (first , last): print ( f"Hello { first } { last } !" ) greeting_firstlast( "Jake" , "Smith" ) greeting_firstlast( "Jonas" , "Bourbon" ) greeting_firstlast( "James" , "McGrill" ) Hello Jake Smith! Hello Jonas Bourbon! Hello James McGrill! # Addition Calculator def add (a , b): print ( f"The first number is: { a } " ) print ( f"The second number is: { b } " ) print ( f"The sum of the two numbers is: { a + b } " ) add( 2 , 3 ) add( 4 , 5 ) add( 6 , 7 ) The first number is: 2 The second number is: 3 The sum of the tw...