0% found this document useful (0 votes)
21 views4 pages

Assignment 2

The document contains a series of programming tasks in Python, including inserting items into a sorted list, removing duplicates while preserving order, and defining various data structures with their characteristics. It also includes exercises on string manipulation, list slicing, accessing nested dictionary values, conditional statements, and calculating tax based on state. Each task requires writing Python code to achieve the specified objectives.

Uploaded by

isrealdaniel863
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Assignment 2

The document contains a series of programming tasks in Python, including inserting items into a sorted list, removing duplicates while preserving order, and defining various data structures with their characteristics. It also includes exercises on string manipulation, list slicing, accessing nested dictionary values, conditional statements, and calculating tax based on state. Each task requires writing Python code to achieve the specified objectives.

Uploaded by

isrealdaniel863
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.) Write a Python program to insert items into a list in sorted order.

Include a Python
function to remove duplicates from a list while preserving the order.

Original List:
[25, 45, 36, 47, 69, 48, 68, 78, 14, 36, 45, 16, 25, 78, 68, 69, 47]

2.) Write out a short definition of all the data structures, including how to create them.
Include type conversion.
Hint. Include their characteristics and when they are best used.
a.) Create an empty list on line 3 and assign its type on line 4

gift_list=

answer_1=

print(answer_1)

Create an empty dictionary on one line, and assign it’s type on the next line.
grocery_items=
answer_2=
print(answer_2)

Create an empty tuple on one line, and assign it’s type on the next line.
bucket_list=
answer_2=
print(answer_2)

3.) Split the verse into a list of words. Hint: You can use a string method you learned in the
previous lesson. Hint: Use

Convert the list into a data structure that would keep only the unique elements
from the list.

Print the length of the container.


verse = "if you can keep your head when all about you are losing theirs and
blaming it on you if you can trust yourself when all men doubt you but make
allowance for their doubting too if you can wait and not be tired by waiting or
being lied about don’t deal in lies or being hated don’t give way to hating and
yet don’t look too good nor talk too wise"

4.) What is the output of the following list operation


aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:]

5.) Select the correct way to access the value of a history subject

sampleDict = {

"class":{

"student":{

"name":"Mike",

"marks":{

"physics":70,

"History":80

6.) What is the output:

x=0

a=5

b=5
if a > 0:

if b < 0:

x=x+5

elif a > 5:

x=x+4

else:

x=x+3

else:

x=x+2

print(x)
print(a)
print(b)

7.) You decide you want to play a game where you are hiding a number from someone. Store
this number in a variable called 'answer'. Another user provides a number called 'guess'.
By comparing 'guess' to 'answer', you inform the user if their guess is too high or too low.
Fill in the conditionals below to inform the user about how their guess compares to the
answer.

Hint - Fill in the conditionals below to inform the user about how their guess compares to
the answer.

answer = 0 #replace 0 with a value you choose


guess = 0 #replace 0 with a value you choose

if #provide conditional
result = "Oops! Your guess was too low."
elif #provide conditional
result = "Oops! Your guess was too high."
else:
result = "Nice! Your guess matched the answer!"
8.) Depending on where an individual is from we need to tax them appropriately. The states
of CA, MN, and NY have taxes of 7.5%, 9.5%, and 8.9% respectively. Use this
information to take the amount of a purchase and the corresponding state to assure that
the right amount taxes them. Explain the process (write it out).
9.)

state = "" #Either "CA", "MN", or "NY"


purchase_amount = #amount of purchase

if #provide conditional for checking state is CA


tax_amount = .075
total_cost = purchase_amount*(1+tax_amount)
result = "Since you're from {}, your total cost is {}.".format(state, total_cost)

elif #provide conditional for checking state is MN


tax_amount = .095
total_cost = purchase_amount*(1+tax_amount)
result = "Since you're from {}, your total cost is {}.".format(state, total_cost)

elif #provide conditional for checking state is NY


tax_amount = .089
total_cost = purchase_amount*(1+tax_amount)
result = "Since you're from {}, your total cost is {}.".format(state, total_cost)

You might also like