Compare commits
17 Commits
6bef49c6b2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 68a61a4b59 | |||
|
|
db5d2fcff3 | ||
|
|
f8530d6f43 | ||
|
|
7badebfecb | ||
|
|
e1e8b21904 | ||
| fe4c7b3701 | |||
|
|
8e662c58bf | ||
|
|
030dd0b611 | ||
|
|
83fb61e63b | ||
|
|
23eec468cf | ||
|
|
b7f73fb1f0 | ||
|
|
b434e7f74f | ||
|
|
763af28c36 | ||
|
|
4fab27a9b0 | ||
|
|
1a9d1f6386 | ||
|
|
50b32271e2 | ||
| d97e42d717 |
2
6/6.12 LAB/main.py
Normal file
2
6/6.12 LAB/main.py
Normal file
@@ -0,0 +1,2 @@
|
||||
user_input = input().split()
|
||||
print(int(sum(map(int, user_input)) / len(user_input)), max(map(int, user_input)))
|
||||
3
6/6.13 LAB/main.py
Normal file
3
6/6.13 LAB/main.py
Normal file
@@ -0,0 +1,3 @@
|
||||
user_input = input().split()
|
||||
|
||||
print(*sorted([i for i in list(map(int, user_input)) if i >= 0]), '', end='')
|
||||
4
6/6.18 LAB/main.py
Normal file
4
6/6.18 LAB/main.py
Normal file
@@ -0,0 +1,4 @@
|
||||
user_input = input().split()
|
||||
|
||||
for element in user_input:
|
||||
print(element, user_input.count(element))
|
||||
9
6/6.19 LAB/main.py
Normal file
9
6/6.19 LAB/main.py
Normal file
@@ -0,0 +1,9 @@
|
||||
replacement_list = dict((k.strip(), v.strip()) for k,v in
|
||||
(item.split() for item in input().split(' ')))
|
||||
|
||||
lab_text = input()
|
||||
|
||||
for element in replacement_list:
|
||||
lab_text = lab_text.replace(element, replacement_list[element])
|
||||
|
||||
print(lab_text)
|
||||
9
6/6.3/6.3.2/main.py
Normal file
9
6/6.3/6.3.2/main.py
Normal file
@@ -0,0 +1,9 @@
|
||||
user_input = input()
|
||||
test_grades = list(map(int, user_input.split())) # test_grades is an integer list of test scores
|
||||
|
||||
|
||||
sum_extra = -999 # Initialize 0 before your loop
|
||||
|
||||
sum_extra = sum([i for i in test_grades if i > 100]) - (len([i for i in test_grades if i > 100]) * 100)
|
||||
|
||||
print('Sum extra:', sum_extra)
|
||||
10
6/6.3/6.3.3/main.py
Normal file
10
6/6.3/6.3.3/main.py
Normal file
@@ -0,0 +1,10 @@
|
||||
user_input = input()
|
||||
hourly_temperature = user_input.split()
|
||||
|
||||
result = []
|
||||
|
||||
for temp in hourly_temperature:
|
||||
result.append(temp)
|
||||
result.append('->')
|
||||
result.pop()
|
||||
print(*result, '')
|
||||
20
6/6.5/6.5.3/main.py
Normal file
20
6/6.5/6.5.3/main.py
Normal file
@@ -0,0 +1,20 @@
|
||||
user_input= input()
|
||||
lines = user_input.split(',')
|
||||
|
||||
# This line uses a construct called a list comprehension, introduced elsewhere,
|
||||
# to convert the input string into a two-dimensional list.
|
||||
# Ex: 1 2, 2 4 is converted to [ [1, 2], [2, 4] ]
|
||||
|
||||
mult_table = [[int(num) for num in line.split()] for line in lines]
|
||||
|
||||
def print_array(array):
|
||||
result = []
|
||||
for row in array:
|
||||
result = []
|
||||
for column in row:
|
||||
result.append(column)
|
||||
result.append('|')
|
||||
result.pop()
|
||||
print(*result)
|
||||
|
||||
print_array(mult_table)
|
||||
1
7/7.8 LAB/input1.csv
Normal file
1
7/7.8 LAB/input1.csv
Normal file
@@ -0,0 +1 @@
|
||||
hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy
|
||||
|
18
7/7.8 LAB/main.py
Normal file
18
7/7.8 LAB/main.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import csv
|
||||
|
||||
with open(input(), newline='') as f:
|
||||
reader = csv.reader(f)
|
||||
data = list(reader)[0]
|
||||
|
||||
result = {}
|
||||
|
||||
for entry in data:
|
||||
try:
|
||||
result[entry]
|
||||
|
||||
result[entry] = result[entry] + 1
|
||||
except KeyError:
|
||||
result[entry] = 1
|
||||
|
||||
for key in result:
|
||||
print('{0} {1}'.format(key, result[key]))
|
||||
12
7/7.9 LAB/file1.txt
Normal file
12
7/7.9 LAB/file1.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
20
|
||||
Gunsmoke
|
||||
30
|
||||
The Simpsons
|
||||
10
|
||||
Will & Grace
|
||||
14
|
||||
Dallas
|
||||
20
|
||||
Law & Order
|
||||
12
|
||||
Murder, She Wrote
|
||||
61
7/7.9 LAB/main.py
Normal file
61
7/7.9 LAB/main.py
Normal file
@@ -0,0 +1,61 @@
|
||||
class MutliKeyDict(dict):
|
||||
"""
|
||||
New Multi Key dict for this application, inherits 'dict'
|
||||
"""
|
||||
def __setitem__(self, key, value): # Overwrites the default __setitem__
|
||||
try:
|
||||
self[key]
|
||||
except KeyError: # If there is a key error (like we append the same season num twice)
|
||||
super(MutliKeyDict, self).__setitem__(key, []) # Make that value a list insted,
|
||||
self[key].append(value) # Append that new list and save
|
||||
|
||||
def pharse_shows(file_location):
|
||||
result = MutliKeyDict()
|
||||
try:
|
||||
with open(file_location) as f:
|
||||
for line in f:
|
||||
season = line.strip("\n")
|
||||
title = next(f).strip("\n")
|
||||
result[season] = title
|
||||
except StopIteration:
|
||||
print('Error pharsing last value, odd number of lines in file?')
|
||||
return(result)
|
||||
|
||||
def save_output_keys(showdict):
|
||||
result = '' # Set the result to a blank string
|
||||
showdict = dict(sorted(showdict.items())) # Sort the dict by key
|
||||
|
||||
for entry in showdict: # For every dict entry in our show dict
|
||||
result += '{0}: '.format(int(entry)) # Append a new line to represent that entry season count
|
||||
if isinstance(showdict[entry], list): # If the entry is a list of shows
|
||||
for show in showdict[entry]: # for very entry in that list of shows
|
||||
result += '{0}; '.format(show) # append that show, and a ";"
|
||||
result = result[:-2] + '\n' # Chop the last ";", ugly but it works. Also add carriage return
|
||||
else: # If the entry is not a list
|
||||
result += '{0}'.format(showdict[entry])
|
||||
|
||||
with open('output_keys.txt', 'w') as f:
|
||||
f.write(result)
|
||||
|
||||
def save_output_titles(showdict):
|
||||
result = [] # Set the result to a blank list
|
||||
for entry in showdict: # For every dict entry in our show dict
|
||||
if isinstance(showdict[entry], list): # If the entry is a list of shows
|
||||
for show in showdict[entry]: # for every entry in that list of shows
|
||||
result.append(show) # Append that show to our result list
|
||||
else: # If the entry is not a list
|
||||
result.append(showdict[entry]) # Append the result directly
|
||||
|
||||
result.sort() # Sort the list
|
||||
|
||||
resultstring = '' # Setup a new blank result string
|
||||
for item in result: # Convert list to stirng, with \n
|
||||
resultstring += str(item) + '\n'
|
||||
|
||||
with open('output_titles.txt', 'w') as f:
|
||||
f.write(resultstring)
|
||||
|
||||
if __name__ == '__main__':
|
||||
showdict = pharse_shows(input())
|
||||
save_output_keys(showdict)
|
||||
save_output_titles(showdict)
|
||||
27
8/8.10 LAB/main.py
Normal file
27
8/8.10 LAB/main.py
Normal file
@@ -0,0 +1,27 @@
|
||||
class Team:
|
||||
def __init__(self):
|
||||
self.team_name = 'none'
|
||||
self.team_wins = 0
|
||||
self.team_losses = 0
|
||||
self.win_percentage = 0
|
||||
|
||||
def get_win_percentage(self):
|
||||
return self.team_wins / (self.team_wins + self.team_losses)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
team = Team()
|
||||
|
||||
team_name = input()
|
||||
team_wins = int(input())
|
||||
team_losses = int(input())
|
||||
|
||||
team.team_name = team_name
|
||||
team.team_wins = team_wins
|
||||
team.team_losses = team_losses
|
||||
|
||||
if team.get_win_percentage() >= 0.5:
|
||||
print('Congratulations, Team', team.team_name,'has a winning average!')
|
||||
else:
|
||||
print('Team', team.team_name, 'has a losing average.')
|
||||
24
8/8.6/8.6.1/main.py
Normal file
24
8/8.6/8.6.1/main.py
Normal file
@@ -0,0 +1,24 @@
|
||||
class PhonePlan:
|
||||
# FIXME add constructor
|
||||
|
||||
def __init__(self, _num_mins=0, _num_messages=0):
|
||||
self.num_mins = _num_mins
|
||||
self.num_messages = _num_messages
|
||||
|
||||
def print_plan(self):
|
||||
print('Mins:', self.num_mins, end=' ')
|
||||
print('Messages:', self.num_messages)
|
||||
|
||||
|
||||
my_plan = PhonePlan(int(input()), int(input()))
|
||||
dads_plan = PhonePlan()
|
||||
moms_plan = PhonePlan(int(input()))
|
||||
|
||||
print('My plan...', end=' ')
|
||||
my_plan.print_plan()
|
||||
|
||||
print('Dad\'s plan...', end=' ')
|
||||
dads_plan.print_plan()
|
||||
|
||||
print('Mom\'s plan...', end= ' ')
|
||||
moms_plan.print_plan()
|
||||
15
8/8.8/8.8.1/main.py
Normal file
15
8/8.8/8.8.1/main.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class CarRecord:
|
||||
def __init__(self):
|
||||
self.year_made = 0
|
||||
self.car_vin = ''
|
||||
|
||||
# FIXME add __str__()
|
||||
|
||||
def __str__(self):
|
||||
return'Year: {0}, VIN: {1}'.format(self.year_made, self.car_vin)
|
||||
|
||||
my_car = CarRecord()
|
||||
my_car.year_made = int(input())
|
||||
my_car.car_vin = input()
|
||||
|
||||
print(my_car)
|
||||
28
8/8.9 LAB/main.py
Normal file
28
8/8.9 LAB/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
class Car:
|
||||
def __init__(self):
|
||||
self.model_year = 0
|
||||
self.purchase_price = 0
|
||||
self.current_value = 0
|
||||
|
||||
def calc_current_value(self, current_year):
|
||||
depreciation_rate = 0.15
|
||||
# Car depreciation formula
|
||||
car_age = current_year - self.model_year
|
||||
self.current_value = round(self.purchase_price * (1 - depreciation_rate) ** car_age)
|
||||
|
||||
def print_info(self):
|
||||
return """Car's information:
|
||||
Model year: {0}
|
||||
Purchase price: {1}
|
||||
Current value: {2}""".format(self.model_year, self.purchase_price, self.current_value)
|
||||
|
||||
if __name__ == "__main__":
|
||||
year = int(input())
|
||||
price = int(input())
|
||||
current_year = int(input())
|
||||
|
||||
my_car = Car()
|
||||
my_car.model_year = year
|
||||
my_car.purchase_price = price
|
||||
my_car.calc_current_value(current_year)
|
||||
print(my_car.print_info())
|
||||
Reference in New Issue
Block a user