#!/usr/bin/env python
# coding: utf-8

# In[1]:


#problem 1: Division
def division(x, y):
    if(y==0):        
        return "Cannot divide by zero"
    else:
        my_result = x/y
        
    return my_result


# In[2]:


result = division(3,5)
print (result)


# In[3]:


result = division(3,0)
print(result)


# In[4]:


#problem 2: Multipy tuple
def multiply_numbers(my_tuple):
    if( len(my_tuple) == 0 ):
        return 0
    else:
        my_total = 1
        for number in my_tuple:
            my_total *= number 
        return my_total


# In[5]:


my_tuple = (1,2,3,4,5,6)
result = multiply_numbers(my_tuple)
print(result)


# In[6]:


#problem 3: String filter
def filter_list(string_list, filter_string):
    new_list = []
    for word in string_list:
        if( word.strip() != filter_string.strip() ):
            new_list.append(word)
    
    return new_list            


# In[7]:


filter_string = 'hello' 
string_list = ['hello', 'dog', 'hello', 'cat'] 
result = filter_list(string_list, filter_string)
print(result)


# In[8]:


filter_string = 'apple' 
string_list = ['apple', 'apple', 'pear', 'apple'] 
result = filter_list(string_list, filter_string)
print(result)


# In[9]:


#problem 4: Lognet word
def longest_word(input_list):
    if( len(input_list) == 0):
        return "List is emptied"
    elif ( len(input_list) == 1 ):
        return input_list[0], 0
    else:
        longest_word = input_list[0]
        longest_word_len = len(longest_word)      
        i = 0        
        longest_index = 0
        for word in input_list:            
            if( longest_word_len < len(word) ) :                
                longest_word = word  
                longest_word_len = len(word)                
                longest_index = i
            i += 1            
                
        return longest_word, longest_index   
        


# In[10]:


word_list = ['cat', 'lama','california', 'penguin'] 
(result, index) = longest_word(word_list) 
print(result + ' at index ' + str(index))


# In[11]:


#problem 5: list_to_unique
def list_to_unique(input_list):
    if( len(input_list) == 0 ):
        return []
    my_set = {input_list[0]}    
    for word in input_list:
        my_set.add(word)
    
    return list(my_set)    


# In[12]:


input_list = ['florida','ohio','ohio','california','california','florida'] 
result = list_to_unique(input_list) 
print(result)


# In[ ]:




