import numpy as np
import astropy.units as u

"""
Explanation: <small><i>Portions of this notebook are based on exercises put together by Jake Vanderplas, though they've been modified to suit the purposes of this course, including expansion/modification of explanations and additional exercises. Source and license info for the original is on GitHub.</i></small>
 Names: [Insert Your Names Here]
Lab 4 - More Practice with Functions
Lab 4 Contents

User-specified Input
More about manipulating strings
Special Characters
Concatenating Strings
Multiple Concatenations
Comparing Strings
More about conditionals
One-line Conditionals
While and Iteration
Break Statements 
Writing and Reading Files with Magic Commands
End of explanation
"""


faren = input("enter a temperature (in Fahrenheit): ")
print(faren)

"""
Explanation: 1. User-Specified Input
Python can also ask the user to specify input interactively, as shown below. Execute the cell to see how it works.
End of explanation
"""


print("green eggs and\n spam")

# Triple quotes are another way to specify multi-line strings
y = """For score and seven minutes ago,
    you folks all learned some basic mathy stuff with Python
    and boy were you blown away!"""
print(y)

"""
Explanation: <div class=hw>
### Exercise 1
-----------------------

Write a function that has no required input, but one optional argument with a default value "C". The function should ask the user what the temperature is and should print that value in Celcius, Farenheit and Kelvin. If the keyword is set to "F" or "K" it should assume the temperature has been given in Farenheit. Otherwise, it should assume Celcius. 

## 2. More About Manipulating Strings

### 2.1 Special Characters

backslashes (`\`) start special (escape) characters:

     \n   = newline  (\r = return)
     \t   = tab
     \a   = bell

string literals are defined with double quotes or quotes.
the outermost quote type cannot be used inside the string (unless it's escaped with a backslash)
End of explanation
"""


# note the ; allows us to do two calculations on the same line
s = "spam" ; e = "eggs"
print(s + e)

print(s + " and " + e)

# this one won't work
print('I want' + 3 + ' eggs and no ' + s)

# but this will
print('I want ' + str(3) + ' eggs and no ' + s)

"""
Explanation: 2.2 Concatenating strings
End of explanation
"""


print(s*3 + e)

print("*" * 50)

"""
Explanation: 2.3 Multiple Concatenations
End of explanation
"""


print("spam" == "good"); print("spam" == "spam")

"spam" < "zoo"

"s" < "spam"

"""
Explanation: 2.4 Comparing Strings
End of explanation
"""


x = 1

if x > 0:
    print("yo")
else:
    print("dude")

# the one line version
"yo" if x > 0 else "dude"

# conditionals can lie within function calls
print("yo" if x > 0 else "dude")

z = "no"

np.sin(np.pi if z=="yes" else 0)

"""
Explanation: <div class=hw>
## Exercise 2
------------------

Write a function that does the following:  
    1) Takes a required input ***string array*** containing the names of the people in your group.  
    2) Asks the person with the longer name for their order first  
    3) Asks each person to enter (using user input) how many eggs they want, and then whether or not they want spam  
    4) prints the order in the form "*name* wants *x* eggs and *[spam/no spam]*" with a new line between the two orders  
    5) prints "name:" + "egg" a number of times equal to the number of eggs ordered + "and" + "SPAM!" or "NO SPAM!" 

## 3. More about Conditionals

### 3.1 One-Line Conditionals
End of explanation
"""


x = 1
y = 0

while y < 10:
    print("yo" if x > 0 else "dude")
    x *= -1
    y += 1

"""
Explanation: 3.2 While and Iteration
End of explanation
"""


#can also do this with a break statement
while True:
    print("yo" if x > 0 else "dude")
    x *= -1
    y += 1
    if y >= 10:
        break

"""
Explanation: <div class=hw>
### Exercise 3
-------------------

Copy the function above into a code cell and add a print statement that prints the variables x and y so that you can see what they are at each step. Use the output to figure out what the statements x \*= -1 and y += 1 are doing. Type an explanation of what they do into a markdown cell

### 3.3 Break Statements 

Break statements allow you to terminate/exit a loop, as in the following example:
End of explanation
"""


%%file number_game.py
# The above "magic" command, denoted with the double %% saves the contents
# of the current cell to file.  We'll see more of these later

x = 0
max_tries = 10
count = 0

while True:
    x_new = int(input("Enter a new number: "))
    if x_new > x:
        print(" -> it's bigger than the last!")
    elif x_new < x:
        print(" -> it's smaller than the last!")
    else:
        print(" -> no change!  I'll exit now")
        break
        
    x = x_new
        
    count += 1
    if count > max_tries:
        print("too many tries...")
        break

%run number_game.py
# this magic command runs the given file. It's like typing python number_game.py in the command line

"""
Explanation: 4. Writing and Reading Files with Magic Commands
End of explanation
"""


4 % 2

4 % 3

6.28 % 3.14

6.28 % 3.1

25 % 5

25 % 7

from IPython.core.display import HTML
def css_styling():
    styles = open("../custom.css", "r").read()
    return HTML(styles)
css_styling()

"""
Explanation: <div class=hw>
### Exercise 4
-------------------

Create a program (and write it to a .py file) which repeatedly asks the user for a word. The program should append all the words together. When the user types a "!", "?", or a ".", the program should print the resulting sentence and exit.
For example, a session might look like this:  

%run exercise2.py  
Enter a word (. ! or ? to end): My  
Enter a word (. ! or ? to end): name  
Enter a word (. ! or ? to end): is  
Enter a word (. ! or ? to end): Walter  
Enter a word (. ! or ? to end): White  
Enter a word (. ! or ? to end): !  

My name is Walter White!

<div class=hw>
### Exercise 5 (a classic)
--------------------

Write a program (and write it to a python file) that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz” instead of the number. A special python operator called modulo and represented with the % sign might help you. A couple of examples of its use are below. See if you can figure out what it does by experimenting.
End of explanation
"""


