Posts

Final Project

  The Guessing Game I decided to create a number guessing game from all the knowledge that I have learned from Python during this semester. Python has a really cool module called random which can generate random values based on your desired conditions I have used it to create a random number guessing game for which you will have 3 tries and the number that you need to guess will be generated randomly from 1 - 10 every time. I only included the number from 1-10 because it will make the game simple and not too harsh for the players to follow up. https://github.com/HungNguyen-usf/PythonProject.git

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...

Module #2 Assignment

After running the following code: print ( 'Hello, world!' ) String1 = 'Welcome to the Geeks World' print ( "String with the use of Single Quotes: " ) print (String1) I get the following result: Hello, world! String with the use of Single Quotes:  Welcome to the Geeks World The print function will display anything inside the bracket to the resulting console, including the string that was put inside the single quotes Since we store the string in a variable called String1 When we print the variable String1, the corresponding string will be printed out on the console