Waheeb Algabri

Q1. What will the following code display?¶

numbers = [1, 2, 3, 4, 5]

print(numbers[1:-5])

Can you debug and fix the output? The code should return the entire list

In [1]:
numbers=[1,2,3,4,5]
print(numbers[0:5])
[1, 2, 3, 4, 5]
Q2. Design a program that asks the user to enter a store’s sales for each day of the week. The amounts should be stored in a list. Use a loop to calculate the total sales for the week and display the result.¶
In [1]:
def sales_tracker():
    weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    tracker = {}
    total_sales = 0  # Initialize a variable to store the total sales

    for day in weekdays:
        sales = int(input(f'Please enter the amount of sale for {day}: '))
        tracker[day] = sales
        total_sales += sales  # Add the daily sales to the total_sales

    return tracker, total_sales

tracker, total_weekly_sales = sales_tracker()
print("Sales Data for the Week:")
print(tracker)
print("Total Sales for the Week:", total_weekly_sales)
Please enter the amount of sale for Monday: 3000
Please enter the amount of sale for Tuesday: 2500
Please enter the amount of sale for Wednesday: 1700
Please enter the amount of sale for Thursday: 1900
Please enter the amount of sale for Friday: 3000
Please enter the amount of sale for Saturday: 3500
Please enter the amount of sale for Sunday: 4000
Sales Data for the Week:
{'Monday': 3000, 'Tuesday': 2500, 'Wednesday': 1700, 'Thursday': 1900, 'Friday': 3000, 'Saturday': 3500, 'Sunday': 4000}
Total Sales for the Week: 19600
Q3. Create a list with at least 5 places you’d like to travel to. Make sure the list isn’t in alphabetical order¶

● Print your list in its original order.

● Use the sort() function to arrange your list in order and reprint your list

● Use the sort(reverse=True) and reprint your list

In [3]:
travel = ["Yemen", "Jordan", "Qater", "Italy", "UK"]
print(travel)
travel.sort()
print(travel)
travel.sort(reverse=True)
print(travel)
['Yemen', 'Jordan', 'Qater', 'Italy', 'UK']
['Italy', 'Jordan', 'Qater', 'UK', 'Yemen']
['Yemen', 'UK', 'Qater', 'Jordan', 'Italy']
Q4. Write a program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The program should also create a dictionary containing course numbers and the names of the instructors that teach each course. After that, the program should let the user enter a course number, then it should display the course’s room number, instructor, and meeting time.¶
In [7]:
number_room = {607:520, 606:286, 602:521, 604:321}
number_instructor_time = {602:["Schettini","6:00 PM EST"], 604:["Fulton", "6:30 PM EST"], 606:["Briar", "8:00 PM EST"], 607:["Catlin", "6:45 PM EST"]}

def course_summary():
  course_number = int(input("Please enter a course number: "))
  print(f"The course number {course_number} meets in room {number_room[course_number]} and has the instructor {number_instructor_time[course_number][0]} and meets at {number_instructor_time[course_number][1]}")

course_summary()
Please enter a course number: 602
The course number 602 meets in room 521 and has the instructor Schettini and meets at 6:00 PM EST
Q5. Write a program that keeps names and email addresses in a dictionary as key-value pairs. The program should then demonstrate the four options:¶

● look up a person’s email address,

● add a new name and email address,

● change an existing email address, and

● delete an existing name and email address.

In [9]:
name_email = {"Waheeb":"Waheeb.Algabri@sps.cuny"}
def name_email_call():
  actions = ["look up","add","change","delete"]
  user_input = input(f"Please choose an action out of {actions}: ")
  if user_input == "look up":
    print(name_email[input("Please enter the name whose email address you want to look up: ")])
  elif user_input == "add":
    new_name = input("Please enter the name of the user you would like to add: ")
    new_email_address = input(f"Please enter the email address of {new_name}: ")
    name_email[new_name] = new_email_address
    print(name_email)
  elif user_input == "change":
    change_name = input("Please enter the name of the user you would like to edit: ")
    change_email_address = input(f"Please enter the new email address of {change_name}: ")
    name_email[change_name] = change_email_address
    print(name_email)
  elif user_input == "delete":
    delete_name = input("Please enter the name of the user you would like to delete: ")
    del name_email[delete_name]
    print(name_email)
  else:
    print("That was an invalid command")
    exit()
name_email_call()
Please choose an action out of ['look up', 'add', 'change', 'delete']: add
Please enter the name of the user you would like to add: Kayleah 
Please enter the email address of Kayleah : Kayleah.sps.cuny
{'Waheeb': 'Waheeb.Algabri@sps.cuny', 'Kayleah ': 'Kayleah.sps.cuny'}