← Back to Portfolio

Midterm Lab Task 1

Escape sequence, User input, Placeholders, and Conditional (Problems 1–4)

Problem #1

Displays basic user information using print statements.

Code


full_name = "John Doe"
_email = "john.doe@example.com"
university_name = "ABC University"

print("Database Record")
print("Name: \t\t\t", full_name)
print("Email: \t\t\t", _email)
print("University: \t", university_name)
        

Output


Database Record
Name:                    John Doe
Email:                   john.doe@example.com
University:              ABC University
        

Problem #2

Shows how to use variables, strings, and formatted output.

Code


message = "Dear John,I hope this email finds you well.\nI wanted to reach out and say hello.\nI hope you are doing well and enjoying your day.\nIt's been a while since we last we spoke, and I wanted to catch up with you.\nLet's plan to meet up soon and have a great time together!"
subj_name = "Jane"
sender_name = "Jane"
ver_num = 1.2
discount = 10.50
status = 'A'
code = "ABCD123"
loc_name = "City XYZ"
_age = 30
company_name = "ABC Corporation"
web_name = "www.example.com"
phone_num = "+1 123-456-7890"
job_title = "Software Engineer"
depart_name = "Engineering"

print("%s \nSubject: %s\nVersion: %.1f" % (message,sender_name,ver_num,))
print("Discount: %.2f" %(discount), end='%\n')
print("Status: %c\nCode: %s\nLocation: %s\nAge: %d\nCompany: %s\nWebsite:%s\nPhone: %s\nJob Tittle: %s\nDepartment: %s" % (status,code,loc_name,_age,company_name,web_name,phone_num,job_title,depart_name))
        

Output


Dear John,I hope this email finds you well.
I wanted to reach out and say hello.
I hope you are doing well and enjoying your day.
It's been a while since we last we spoke, and I wanted to catch up with you.
Let's plan to meet up soon and have a great time together! 
Subject: Jane
Version: 1.2
Discount: 10.50%
Status: A
Code: ABCD123
Location: City XYZ
Age: 30
Company: ABC Corporation
Website:www.example.com
Phone: +1 123-456-7890
Job Tittle: Software Engineer
Department: Engineering
        

Problem #3

Demonstrates input collection and string formatting for displaying book information.

Code


title = input("Enter the book title: ")
author = input("Enter the author: ")
publication = input("Enter the year of publication: ")
genre_name = input("Enter the genre: ")
lib_name = input("Enter the library: ")
memID = input("Enter your memberID: ")
return_date = input("Enter the return date: ")

print("You have successfully reserved the book '%s' by %s." % (title, author))
print("Year of Publication: %d" % (publication))
print("Genre: %s" % (genre_name))
print("Library: %s" % (lib_name))
print("Member ID: %d" % (memID))
print("Return Date: %s" % (return_date))
        

Outputs


Enter the book title: 1984
Enter the author: Orwell
Enter the year of publication: 1949
Enter the genre: Dystopian
Enter the library: Central
Enter your memberID: 12345
Enter the return date: 2023-07-10
You have successfully reserved the book '1984' by Orwell.
Year of Publication: 1949
Genre: Dystopian
Library: Central
Member ID: 12345
Return Date: 2023-07-10
        

Enter the book title: Mockingbird
Enter the author: Lee
Enter the year of publication: 1960
Enter the genre: Fiction
Enter the library: Westside
Enter your memberID: 67890
Enter the return date: 2023-06-28
You have successfully reserved the book 'Mockingbird' by Lee.
Year of Publication: 1960
Genre: Fiction
Library: Westside
Member ID: 67890
Return Date: 2023-06-28
        

Problem #4

Shows conditional statements to display the day of the week based on user input.

Code


day = int(input("Enter Day number (1-7): "))

if day == 1:
    print("Monday")
elif day == 2:
    print("Tuesday")
elif day == 3:
    print("Wednesday")
elif day == 4:
    print("Thursday")
elif day == 5:
    print("Friday")
elif day == 6:
    print("Saturday")
elif day == 7:
    print("Sunday")
else:
    print("Invalid input")
        

Outputs


Enter day: 1
Monday
        

Enter day: 4
Thursday
        

Enter day: 5
Friday
        
View PDF Here