573 Python Practice

¡Supera tus tareas y exámenes ahora con Quizwiz!

The data element contains a string comprised of two integers separated by a space. Add them together and submit the sum

def d0(y): return sum(map(int,y.split()))

The data element contains a long string. Extract the substring that is surrounded by dashes. Submit that substring.

def d1(y): return y.split('-')[1]

The data contains your current driving speed and an excuse. The speed limit is 15 MPH on post and you just got pulled over. If you are not speeding there is no fine. If your speed is less than 5MPH over the limit then you are fined $20.00. If your speed is 5 MPH or more over the limit you are fined $40.00. However you can try various excuses on the MPs. If your excuse is "I am headed to the hospital" no fine is issued. If your excuse is "I work at the NSA" the fine doesn't change. If your excuse is "I work at Signal Towers" the fine is doubled. Any other excuse cuts the fine in half. Submit the fine as an integer {No Dollar signs, no decimal points}.

def d10(y): sp=(y.split(','))[0] ex=(y.split(','))[1] sp=int(sp) if sp<=15: return 0 elif sp<20: fine=20 else: fine=40 if ex=="I am headed to the hosplital": fine=0 elif ex=="I work at the NSA": fine=fine elif ex=="I work at Signal Towers": fine=fine*2 else: fine=fine/2

Add together all of the unique numbers in the string. If a number is not unique do not include it in the total. Example: 1,1,2,3,4,4 would be 5.

def d11(y): return sum([int(x) for x in y.split(',') if y.split(',').count(x)==1])

If you are flying Delta airlines and it is raining your flight will be delayed. If you are in Atlanta, GA, your flight will be delayed regardless of weather. The data element contains your airline, the weather and your location. Return "delayed" or "not-delayed".

def d12(y): air=y.split(',')[0] wet=y.split(',')[1] loc=y.split(',')[2] if air=='Delta' and wet=='raining' : return "Delayed" elif loc=="atlanta": return "Delayed" else: return "Not-delayed"

Return the 2nd word in the sentence in reverse. Example: " The quick brown fox." would be kciuq.

def d2(y): return (y.split())[1][::-1]

Base64 decode the string and submit the answer.

def d3(y): return y.decode('base64')

It is currently 2130 hours. The data element contains how many hours are left on your shift as a towel handler at gym #5. What time will it be when your shift ends. Express your answer in proper military time. Example: 0130.

def d4(y): return '%d30' % ((21+y) % 24)

Cut the string in half and submit the 2nd half. Example "Hello World" would be "World".

def d5(y): return y[len(y)/2:]

Convert the base16 string to a decimal number. Example "0xFF" would be 255".

def d6(y): return int(y,16)

The data contains a list. What is the 3rd item in the list?

def d7(y): return y[2]

The data contains a dictionary. What is the value in the entry with a key of "cyber"?

def d8(y): return y['cyber']

The data contains a string of numbers separated by commas. Add together all the numbers and submit the total.

def d9(y): return sum(map(int,y.split(',')))


Conjuntos de estudio relacionados

Chapter 41: Care of the Surgical Patient

View Set

Lesson 118 - First Semester Final Exam

View Set

Depressive Disorders & Bipolar and Related Disorders

View Set

Chapter 1 - Psychoactive Drugs: Classification & History

View Set

Manufacturing Processes Chapter 21

View Set

Fire inspector set ch 1-12 for state test

View Set

Triangular Trade/Slave Trade (Cultural Exchange pages 11-12)

View Set

303 Hinkle PrepU Chapter 61: Management of Patients with Dermatologic Disorders

View Set