<jupyter_start><jupyter_text><NAME>- 1/11/2022- 7:58 PM- Workshop turn it in  Workshop 1 This notebook will cover the following topics:1. Basic Input/Output and formatting2. Decision Structure and Boolean Logic3. Basic Loop Structures4. Data Structures  1.1 Basic Input/Output and formatting (Follow):  **Learning Objectives:**    1. Perform basic input and output for a user    2. Format input and output    3. Perform basic math on input and output    4. Understand different datatypes<jupyter_code># Add comments below 

# This is a normal string print
print ("This is a print statement")
# This is is f tring print with number
print (f"Try printing some different things including number {5}")

# Get input from user and store in input_string
input_string = input("Enter a short string here:")

# Display the user input
print ("The string you input is: ", input_string)

# define float_number value 2
float_number = 2
# print the float number with 2 decimal place format
print("This will print a float number with 2 decimal places: ", format(float_number, '.2f'))

num1 = 5
num2 = 10
print("This will multiply {num1} times {num2} and display the result: ", num1*num2)<jupyter_output>This is a print statement
Try printing some different things including number 5
Enter a short string here:234
The string you input is:  234
This will print a float number with 2 decimal places:  2.00
This will multiply {num1} times {num2} and display the result:  50<jupyter_text>1.1 Basic Input/Output and formatting (Group):  1. Create a small program that will take a celcius temperature from the user and convert it to fahrenheit2. Print the output result to 3 decimal places3. Print a degree sign after the output4. Try to figure out how to create the program in the fewest lines possible Fahrenheit = (9/5)(Degrees Celcius) + 32<jupyter_code>def calculate_fahrenheit(celcius_degree):
    return (f"The degree in Fahrenheit is {format((float(celcius_degree)*9)/5+32,'.3f')} \N{DEGREE SIGN}F")
cel_input = input('Please enter a degree in celius: ')
print(calculate_fahrenheit(cel_input))<jupyter_output>Please enter a degree in celius: 23
The degree in Fahrenheit is 73.400 °F<jupyter_text>1.2 Decision Structure and Boolean Logic (Follow):  **Learning Objectives:**    1. Understand boolean logic and logical operators    2. Understand If/Else statements and program flow<jupyter_code>#Add comments below 

day = int(input('Enter a number (1-7) for the day of the week: '))

if day == 1:
    print('Monday')
elif day == 2:
    print('Tuesday')
elif day == 3:
    print('Wednesday')
elif day == 4:
    print ('Thursday')
elif day == 5:
    print ('Friday')
elif day == 6:
    print ('Saturday')
elif day == 7:
    print ('Sunday')
else:
    print ('Error: Please enter a number in the range 1-7.')<jupyter_output>Enter a number (1-7) for the day of the week: 1
Monday<jupyter_text>After running this program, think about and answer these questions:1. What is the program doing?2. Does every line in the code execute, explain?3. Could you find a way to break it?  Answer:1. What is the program doing: The program print out the day of the week with respective number (start with 1 for Monday and 7 for Sunday)2. Does every line in the code execute: Yes, everyline of code execute with taking input then go through if-elif-else condition (All the syntax and else if else is in correct order and connected)3. Could you find a way to break it: Yes, just enter a string and it will break. I include a solution below to fix this bby validation the input inside the function instead parse it in the get input<jupyter_code>def day_of_week(number):
    if number.isdigit() and int(number) in range(1,8):
        week_days=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday','Saturday','Sunday']
        print(week_days[int(number)-1])
    else:
        print('Please enter a number from 1 to 7 only!')
day = input('Enter a number (1-7) for the day of the week: ')
day_of_week(day)
#Add comments below 

RED = 'red'
BLUE = 'blue'
YELLOW = 'yellow'

color1 = input('Enter the first primary color in lower case letters: ')

color2 = input('Enter the second primary color in lower case letters: ')

if color1 != RED and color1 != BLUE and color1 != YELLOW:
    print('Error: The first color you entered is invalid.')

elif color2 != RED and color2 != BLUE and color2 != YELLOW:
    print('Error: The second color you entered is invalid.')

elif color1 == color2:
    print('Error: The two colors you entered are the same.')

else:
    if color1 == RED:
        if color2 == BLUE:
            print('purple')
        else: 
            print('orange')

    elif color1 == BLUE:
        if color2 == RED:
            print('purple')
        else: 
            print('green')

    else: 
        if color2 == RED:
            print('orange')
        else: 
            print('green')<jupyter_output>Enter the first primary color in lower case letters: dsfus9df8s9dsdf
Enter the second primary color in lower case letters: sdf
Error: The first color you entered is invalid.<jupyter_text>After running this program, think about and answer these questions:1. What is the program doing?2. Does every line in the code execute, explain?3. Could you find a way to break it?4. Replace the 'ands' with 'ors' and discuss how the program executes now.  Answer:After running this program, think about and answer these questions:1. What is the program doing: Program take 2 color of user input (out of 3 color: red, blue green) and output the mixed color of user input's color. The prgram also validate the user input to make sure input is validate2. Does every line in the code execute, explain: Yes, every line of code is execute. The code follow if-elif-else nested if structure and corrected indent. Therefore, every line of code is executed.3. Could you find a way to break it? Nope, it is well structure and cant break. The only missing case is both color 1 and color is invalid, it would be nice to print it out.4. Replace the 'ands' with 'ors' and discuss how the program executes now: Well if we add the or program will not run correctly. We are now encounter a logic error. For example in the 1st if statement, if user enter BLUE or YELLOW, the app will ignore them. it will still print out the invalid satatement eventhough the BLUE and GREEN is valid. The reason is the 'or' statement just make the print statement execute because it satisied the condition color is not 'RED'.  1.2 Decision Structure and Boolean Logic (Group):  Develop a program that will do the following:1. Take input from the user for length and width for two different sets of numbers. Fours total inputs.2. Multiply the length and width together and find the area for the two different sets of numbers.3. Compare the areas and print which one is larger.4. Be sure to handle non-numeric inputs.<jupyter_code>def compare_area(length1, width1, length2, width2):
    if length1.isdigit() and length2.isdigit() and width1.isdigit() and width2.isdigit():
        area1=int(length1)*int(width1)
        area2=int(length2)*int(width2)
        print (f"Area of reactangle 1 is: {area1}")
        print (f"Area of reactangle 2 is: {area2}")
        print("Rectangle 1 have bigger area than Rectangle 2" 
              if area1 > area2 else "Rectangle 2 have bigger area than Rectangle 1")
    else:
        print("Application only take integer only")
    
length1 = input("Please enter the length of object 1: ")
width1 = input("Please enter the width of object 1: ")
length2 = input("Please enter the length of object 2: ")
width2 = input("Please enter the width of object 2: ")

compare_area(length1, width1, length2, width2)<jupyter_output><empty_output><jupyter_text>1.3 Basic loop structures (Follow):**Learning Objectives:**    1. Understanding repetative structures    2. Understanding while loops    3. Understanding for loops    4. Nested loops and order N run time<jupyter_code>#Add comments below

number = 1.0    
total = 0.0

# If number smaller than 0 app will stop working
while number > 0:
    number = float(input('Enter a positive number (negative to quit): '))
    if number > 0:
        total = total + number

print (f'Total = {total:.2f}')<jupyter_output>Enter a positive number (negative to quit): 4
Enter a positive number (negative to quit): -5
Total = 4.00<jupyter_text>After running this program, think about and answer these questions:1. What is the program doing?2. How many time does each line in the code execute, explain?3. Could you find a way to break it?4. Try to rewrite the program using a for loop.<jupyter_code># Add comments to the program

caloriesPerMinute = 4.2

caloriesBurned = 0.0

print ('Minutes\t\tCalories Burned')
print ('-------------------------------')

# for miniute in range 10 to 30, increase by 5
for minutes in range(10, 31, 5):
    caloriesBurned = caloriesPerMinute * minutes
    print (minutes, "\t\t", caloriesBurned)<jupyter_output>Minutes		Calories Burned
-------------------------------
10 		 42.0
15 		 63.0
20 		 84.0
25 		 105.0
30 		 126.0<jupyter_text>After running this program, think about and answer these questions:1. What is the program doing?2. How many time does each line in the code execute, explain?3. Could you find a way to break it?4. Try to rewrite the program using a while loop.<jupyter_code>###### Add comments to the program 

totalRainfall = 0.0
monthRainfall = 0.0
averageRainfall = 0.0
years = 0
totalMonths = 0

years = int(input('Enter the number of years: '))

for year in range(years):
    print (f'For year {year + 1}:')
    for month in range(12):
        monthRainfall = float(input('Enter the rainfall amount for the month: '))
        totalMonths += 1
        totalRainfall += monthRainfall
        
averageRainfall = totalRainfall / totalMonths

print(f'For {totalMonths} months')
print(f'Total rainfall: {totalRainfall:,.2f} inches')
print(f'Average monthly rainfall: {averageRainfall:,.2f} inches')<jupyter_output>Enter the number of years:<jupyter_text>After running this program, think about and answer these questions:1. What is the program doing?2. How many time does each line in the code execute, explain?3. Could you find a way to break it?4. Compare the number of executuions for the inner for loop to the outer for loop.5. What order of magnitude larger are the inner instructions executing?  1.3 Basic loop structures (Group):Develop a program that will:1. Take input from the user asking how many organisms to start with.2. Take input from the user asking the average daily increase for the organisms.3. Take input from the user asking the number of days to multiply.4. Make sure the daily increase was entered as a percentage, if not correct it.5. Print each day and the increase in organsisms for each day. 6. Make sure to format the printing so that it is readable.<jupyter_code>organism_size = int(input('please enter your organisms to start with here: '))
percentage  = float(input('please enter your percentage here (format: 00.00): '))
day_count = int(input('please enter your number of days to multiply: '))

for i in range (day_count):
    organism_size +=  organism_size*percentage
    print(f"On day {i+1}, the {organism_size}" )<jupyter_output>please enter your organisms to start with here: 123
please enter your percentage here (format: 00.00): .12
please enter your number of days to multiply: 23
On day 1, the 137.76
On day 2, the 154.2912
On day 3, the 172.80614400000002
On day 4, the 193.54288128000002
On day 5, the 216.76802703360002
On day 6, the 242.78019027763202
On day 7, the 271.91381311094784
On day 8, the 304.5434706842616
On day 9, the 341.088687166373
On day 10, the 382.01932962633776
On day 11, the 427.8616491814983
On day 12, the 479.2050470832781
On day 13, the 536.7096527332715
On day 14, the 601.114811061264
On day 15, the 673.2485883886158
On day 16, the 754.0384189952497
On day 17, the 844.5230292746796
On day 18, the 945.8657927876412
On day 19, the 1059.3696879221582
On day 20, the 1186.4940504728172
On day 21, the 1328.8733365295552
On day 22, the 1488.3381369131018
On day 23, the 1666.938713342674<jupyter_text>1.4 Data Structures (Follow):**Learning Objectives:**    1. Understand list and tuples    2. Understand dictionaries and sets    3. Understand strings<jupyter_code># Add comments to the program
total_sales = 0.0

# define tupples
daily_sales_tuple = (7.0, 5.0, 3.2, 1.7, 6.0, 4.9, 1.1) 
daily_sales_list = [7.0, 5.0, 3.2, 1.7, 6.0, 4.9, 1.1]

# define days of week list
days_of_week = ['Sunday', 'Monday', 'Tuesday',
                    'Wednesday', 'Thursday', 'Friday',
                    'Saturday']

for number in daily_sales_list:
        total_sales += number

print (f'Total sales for the week: ${total_sales:,.2f}')

total_sales = 0.0
for number in daily_sales_tuple:
        total_sales += number

print (f'Total sales for the week: ${total_sales:,.2f}')


print (f'Sales per day: ')
for i in range(7):
        print(f"{days_of_week[i] : <10}", f"{daily_sales_list[i] : >20}")
        print(f"{days_of_week[i] : <10}", f"{daily_sales_tuple[i] : >20}")
        
daily_sales_list[5] = 10.0 
#daily_sales_tuple[5] = 10.0  #uncomment this line to see what happens

new_value = 3.2
daily_sales_list.append(new_value)
new_daily_sales_tuple = daily_sales_tuple + (new_value,)

days_of_week.append('Sunday')

print("")
print (f'Sales per day: ')
for i in range(len(days_of_week)):
        print(f"{days_of_week[i] : <10}", f"{daily_sales_list[i] : >20}")
        print(f"{days_of_week[i] : <10}", f"{new_daily_sales_tuple[i] : >20}")<jupyter_output><empty_output><jupyter_text>After running the above code, think about and answer the following questions:1. What is the program doing?2. What does the append function do?3. Which actual entry is changed when setting daily sales[5] to 10?4. Discuss and the similarities and differences between lists and tuples.<jupyter_code># Add comments to the program

import random

capitals = {'Alabama':'Montgomery', 'Alaska':'Juneau',
                'Arizona':'Phoenix', 'Arkansas':'Little Rock',
                'California':'Sacramento', 'Colorado':'Denver',
                'Connecticut':'Hartford', 'Delaware':'Dover',
                'Florida':'Tallahassee', 'Georgia':'Atlanta',
                'Hawaii':'Honolulu', 'Idaho':'Boise',
                'Illinois':'Springfield', 'Indiana':'Indianapolis',
                'Iowa':'Des Moines', 'Kansas':'Topeka',
                'Kentucky':'Frankfort', 'Louisiana':'Baton Rouge',
                'Maine':'Augusta', 'Maryland':'Annapolis',
                'Massachusetts':'Boston', 'Michigan':'Lansing',
                'Minnesota':'Saint Paul', 'Mississippi':'Jackson',
                'Missouri':'Jefferson City', 'Montana':'Helena',
                'Nebraska':'Lincoln', 'Nevada':'Carson City',
                'New Hampshire':'Concord', 'New Jersey':'Trenton',
                'New Mexico':'Santa Fe', 'New York':'Albany',
                'North Carolina':'Raleigh', 'North Dakota':'Bismarck',
                'Ohio':'Columbus', 'Oklahoma':'Oklahoma City',
                'Oregon':'Salem', 'Pennsylvania':'Harrisburg',
                'Rhode Island':'Providence', 'South Carolina':'Columbia',
                'South Dakota':'Pierre', 'Tennessee':'Nashville',
                'Texas':'Austin', 'Utah':'Salt Lake City',
                'Vermont':'Montpelier', 'Virginia':'Richmond',
                'Washington':'Olympia', 'West Virginia':'Charleston',
                'Wisconsin':'Madison', 'Wyoming':'Cheyenne'}
                
correct = 0
wrong = 0
next_question = True
index = 0
user_solution = ''


while next_question:

    state_iterator = iter(capitals)
        
    index = (random.randint(1,50) - 1)
    for i in range (index-1):
        temp = state_iterator.__next__()
    current_state = str(state_iterator.__next__())

    user_solution = input(f'What is the capital of {current_state}? 'f'(or enter 0 to quit): ')
        
    if user_solution == '0': 
        next_question = False
        print(f'You had {correct} correct responses and 'f'{wrong} incorrect responses.')  
        
    elif user_solution == capitals[current_state]:
        correct = correct + 1
        print('That is correct.')
        
    else:
        wrong = wrong + 1
        print('That is incorrect.')<jupyter_output><empty_output><jupyter_text>After running the above code, think about and answer the following questions:1. What is the program doing?2. What does a key in a dictionary do? What does the value in a dictionary do?3. Where would you be more likely to use a dictionary versus using a list or tuple?4. How are dictionaries different from tuples and lists?<jupyter_code># add comments to the program

baseball = set(['Jodi', 'Carmen', 'Aida', 'Alicia'])
basketball = set(['Eva', 'Carmen', 'Alicia', 'Sarah'])

print('The following students are on the baseball team:')
for name in baseball:
    print(name)

print()
print('The following students are on the basketball team:')
for name in basketball:
    print(name)

print()
print('The following students play both baseball and basketball:')
for name in baseball.intersection(basketball):
    print(name)

print()
print('The following students play either baseball or basketball:')
for name in baseball.union(basketball):
    print(name)

print()
print('The following students play baseball, but not basketball:')
for name in baseball.difference(basketball):
    print(name)

print()
print('The following students play basketball, but not baseball:')
for name in basketball.difference(baseball):
    print(name)

print()
print('The following students play one sport, but not both:')
for name in baseball.symmetric_difference(basketball):
    print(name)<jupyter_output><empty_output><jupyter_text>After running the above code, think about and answer the following questions:1. What is the program doing?2. What does a set do and how is it used above?3. Where would you be more likely to use a set versus using a dictionary, list, or tuple?4. How are sets different from dictionaries, tuples, and lists?  1.4 Data Structures (Group):Create a program that does the following:1. Take the two lists provided and count the frequency of each word in each list.2. Create a dictionary with the key equal to each unique word and count as the value.3. Print off a list of words that are in both lists.4. Print off a list of words that are in the first list and not the second.5. Print off a list of words that are in the second list and not in the first.<jupyter_code>list1 = ['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']

list2 = ['jack', 'be', 'nimble', 'jack', 'be', 'quick', 'jack', 'jumps', 'over', 'the', 'candlestick']

def count_character(list_):
    dictlist = {}
    for words in list_:
        if words is not in dictlist:
            dictlist[words]=1
        else:
            dictlist[words]+=1
            
dict1 = count_character(list1)
dict2 = count_character(list2)
set1 = set(list1)
set2 = set(list2)

print('The words in both list:')
for word in set1.intersection(set2):
    print(word)

print('words that are in the first list:')
for word in set1.difference(set2)
    print(word)

print('words that are in the second list:')
for word in set2.difference(set1)
    print(word)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10125336648021545, 'fraction_numerical': 0.04148539465506526, 'mean_word_length': 3.7535696701132446, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '33310', 'license': 'MIT', 'n_tokens_mistral': 6412, 'n_tokens_neox': 5668, 'n_words': 2379, 'path': 'src/WSK Week1.ipynb', 'repo_name': 'jackyhuynh/master-python-fundamental-in-10-lessons', 'size': '19312'}