diff --git a/3 calcGUI/ChristinaTimokhinCalcGui b/3 calcGUI/ChristinaTimokhinCalcGui new file mode 100644 index 0000000..86281ef --- /dev/null +++ b/3 calcGUI/ChristinaTimokhinCalcGui @@ -0,0 +1,238 @@ +''' +Modified calcGUI +This example helps show how the tkinter library works in Python. +Run it and press the 1 key on your keyboard. Why does "dominic" appear in the entry bar? +Why does one key have "DT" on it? When you click it, why does it make "Thomas" show in the entry bar? +Why is the font in the entry bar now fancy? +How would we add more buttons? +''' + +from tkinter import * +from math import sqrt as sqr + + +class Calculator(Frame): + """ + An example of a calculator app developed using the + Tkinter GUI. + """ + + def __init__(self, master): + """ + Initializes the frame. + :param master: root.Tk() + """ + Frame.__init__(self, master) + self.entry = Entry(master, width=32, font=("Brush Script MT",25)) + self.entry.grid(row=0, column=0, columnspan=6, sticky="w") + self.entry.focus_set() + self.entry.configure(state="disabled", disabledbackground="white", disabledforeground="black") + self.create_widgets() + self.bind_buttons(master) + self.grid() + + def add_chr(self, char, btn=None): + """ + Concatenates a character passed from a button press (or key type) + to a string. + :param char: string to add passed from a button + :param btn: button name to use if key is pressed (to flash) + :return: None + """ + self.entry.configure(state="normal") + self.flash(btn) # Flash a button correspond to keystroke + if self.entry.get() == "Invalid Input": + self.entry.delete(0,END) + self.entry.insert(END, char) + self.entry.configure(state="disabled") + + def clear(self): + """ + Allows user to backspace their entry. + :return: None + """ + self.entry.configure(state="normal") + if self.entry.get() != "Invalid Input": + # Clears full entry when "Invalid Input" + text = self.entry.get()[:-1] + self.entry.delete(0,END) + self.entry.insert(0,text) + else: + self.entry.delete(0, END) + self.entry.configure(state="disabled") + + def clear_all(self): + """ + Allows user to clear the full entry. + :return: None + """ + self.entry.configure(state="normal") + self.entry.delete(0, END) + self.entry.configure(state="disabled") + + def calculate(self): + """ + Changes the operation symbols to their mathematical representation used in + the eval() method. + :return: None + """ + self.entry.configure(state="normal") + e = self.entry.get() + e = e.replace("√","sqr") + e = e.replace("×", "*") + e = e.replace("²", "**2") + e = e.replace("^", "**") + e = e.replace("÷", "/") + + try: + ans = eval(e) + except Exception as ex: + self.entry.delete(0,END) + self.entry.insert(0, "Invalid Input") + else: + self.entry.delete(0,END) + if len(str(ans)) > 20: # Alleviates problem of large numbers + self.entry.insert(0, '{:.10e}'.format(ans)) + else: + self.entry.insert(0, ans) + self.entry.configure(state="disabled") + + def flash(self,btn): + """ + Flashes a corresponding button when key is pressed. + :param btn: button + :return: None + """ + if btn != None: + btn.config(bg="yellow") + if btn == self.c_bttn: + self.clear() + self.master.after(100, lambda: btn.config(bg="SystemButtonFace")) + elif btn == self.eq_bttn: + self.master.after(100, lambda: btn.config(bg="lightgrey")) + self.calculate() + elif btn == self.ac_bttn: + self.clear_all() + self.master.after(100, lambda: btn.config(bg="SystemButtonFace")) + else: + self.master.after(100, lambda: btn.config(bg="SystemButtonFace")) + else: + pass + + def bind_buttons(self, master): + """ + Binds keys to their appropriate input + :param master: root.Tk() + :return: None + """ + master.bind("", lambda event, btn=self.eq_bttn: self.flash(btn)) + master.bind("", lambda event, btn=self.c_bttn: self.flash(btn)) + master.bind("9", lambda event, char="9", btn=self.nine_bttn: self.add_chr(char, btn)) + master.bind("8", lambda event, char="8", btn=self.eight_bttn: self.add_chr(char, btn)) + master.bind("7", lambda event, char="7", btn=self.seven_bttn: self.add_chr(char, btn)) + master.bind("6", lambda event, char="6", btn=self.six_bttn: self.add_chr(char, btn)) + master.bind("5", lambda event, char="5", btn=self.five_bttn: self.add_chr(char, btn)) + master.bind("4", lambda event, char="4", btn=self.four_bttn: self.add_chr(char, btn)) + master.bind("3", lambda event, char="3", btn=self.three_bttn: self.add_chr(char, btn)) + master.bind("2", lambda event, char="2", btn=self.two_bttn: self.add_chr(char, btn)) + master.bind("1", lambda event, char="Dominic", btn=self.one_bttn: self.add_chr(char, btn)) + master.bind("0", lambda event, char="0", btn=self.zero_bttn: self.add_chr(char, btn)) + master.bind("*", lambda event, char="×", btn=self.mult_bttn: self.add_chr(char, btn)) + master.bind("/", lambda event, char="÷", btn=self.div_bttn: self.add_chr(char, btn)) + master.bind("^", lambda event, char="^", btn=self.sqr_bttn: self.add_chr(char, btn)) + master.bind("%", lambda event, char="%", btn=self.mod_bttn: self.add_chr(char, btn)) + master.bind(".", lambda event, char=".", btn=self.dec_bttn: self.add_chr(char, btn)) + master.bind("-", lambda event, char="-", btn=self.sub_bttn: self.add_chr(char, btn)) + master.bind("+", lambda event, char="+", btn=self.add_bttn: self.add_chr(char, btn)) + master.bind("(", lambda event, char="(", btn=self.lpar_bttn: self.add_chr(char, btn)) + master.bind(")", lambda event, char=")", btn=self.rpar_bttn: self.add_chr(char, btn)) + master.bind("c", lambda event, btn=self.ac_bttn: self.flash(btn), self.clear_all) + + def create_widgets(self): + """ + Creates the widgets to be used in the grid. + :return: None + """ + self.eq_bttn = Button(self, text="=", width=20, height=3, bg="Orange", command=lambda: self.calculate()) + self.eq_bttn.grid(row=4, column=4, columnspan=2) + + self.ac_bttn = Button(self, text='CE', width=9, height=3, bg='LightBlue', fg='red',command=lambda: self.clear_all()) + self.ac_bttn.grid(row=1, column=4) + + self.c_bttn = Button(self, text='←', width=9, height=3, bg='LightBlue', fg='red',command=lambda: self.clear()) + self.c_bttn.grid(row=1, column=5 ) + + self.add_bttn = Button(self, text="+", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('+')) + self.add_bttn.grid(row=4, column=3) + + self.mult_bttn = Button(self, text="×", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('×')) + self.mult_bttn.grid(row=2, column=3) + + self.sub_bttn = Button(self, text="-", width=9, height=3, bg='LightBlue', fg='red',command=lambda: self.add_chr('-')) + self.sub_bttn.grid(row=3, column=3) + + self.div_bttn = Button(self, text="÷", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('/')) + self.div_bttn.grid(row=1, column=3) + + self.mod_bttn = Button(self, text="%", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('%')) + self.mod_bttn.grid(row=4, column=2) + + self.seven_bttn = Button(self, text="7", width=9, height=3, bg='LightBlue', fg='red',command=lambda: self.add_chr("7")) + self.seven_bttn.grid(row=1, column=0) + + self.eight_bttn = Button(self, text="8", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(8)) + self.eight_bttn.grid(row=1, column=1) + + self.nine_bttn = Button(self, text="9", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(9)) + self.nine_bttn.grid(row=1, column=2) + + self.four_bttn = Button(self, text="4", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(4)) + self.four_bttn.grid(row=2, column=0) + + self.five_bttn = Button(self, text="5", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(5)) + self.five_bttn.grid(row=2, column=1) + + self.six_bttn = Button(self, text="6", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(6)) + self.six_bttn.grid(row=2, column=2) + + self.one_bttn = Button(self, text="Christina", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr("Timokhin")) + self.one_bttn.grid(row=3, column=0) + + self.two_bttn = Button(self, text="DT", width=9, height=3, bg='LightBlue', fg='red',command=lambda: self.add_chr("Thomas")) + self.two_bttn.grid(row=3, column=1) + + self.three_bttn = Button(self, text="3", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(3)) + self.three_bttn.grid(row=3, column=2) + + self.zero_bttn = Button(self, text="0", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(0)) + self.zero_bttn.grid(row=4, column=0) + + self.dec_bttn = Button(self, text=".", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('.')) + self.dec_bttn.grid(row=4, column=1) + + self.lpar_bttn = Button(self, text="(", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('(')) + self.lpar_bttn.grid(row=2, column=4) + + self.rpar_bttn = Button(self, text=")", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr(')')) + self.rpar_bttn.grid(row=2, column=5) + + self.sq_bttn = Button(self, text="√", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('√(')) + self.sq_bttn.grid(row=3, column=4) + + self.sqr_bttn = Button(self, text="^", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('^')) + self.sqr_bttn.grid(row=3, column=5) + + self.sin_btn = Button(self, text="sin", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('SIN')) + self.sin_btn.grid(row=1, column=6) + + self.cos_btn = Button(self, text="cos", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('COS')) + self.cos_btn.grid(row=2, column=6) + + self.tan_btn = Button(self, text="tan", width=9, height=3,bg='LightBlue', fg='red', command=lambda: self.add_chr('TAN')) + self.tan_btn.grid(row=3, column=6) + +root = Tk() +root.geometry() +root.title("Modified GUI Calculator") +app = Calculator(root) +root.mainloop() \ No newline at end of file diff --git a/Python Absolute Beginner/P1M1_Christina_Timokhin.py b/Python Absolute Beginner/P1M1_Christina_Timokhin.py new file mode 100644 index 0000000..8d5bd1f --- /dev/null +++ b/Python Absolute Beginner/P1M1_Christina_Timokhin.py @@ -0,0 +1,19 @@ +# Allergy check + +# 1[ ] get input for test +input_test = input("Enter food categories: ") + +# 2/3[ ] print True if "dairy" is in the input or False if not +print("Dairy:","dairy" in input_test) + +# 4[ ] Check if "nuts" are in the input +print("Nuts:","nuts" in input_test) + +# 4+[ ] Challenge: Check if "seafood" is in the input +print("Seafood:","seafood" in input_test) + +# 4+[ ] Challenge: Check if "chocolate" is in the input +print("Chocolate:","chocolate" in input_test) + +# user input +# cheese egg nuts candy sugar \ No newline at end of file diff --git a/Python Absolute Beginner/P1M1_Christina_Timokhin_full.py b/Python Absolute Beginner/P1M1_Christina_Timokhin_full.py new file mode 100644 index 0000000..f931e67 --- /dev/null +++ b/Python Absolute Beginner/P1M1_Christina_Timokhin_full.py @@ -0,0 +1,615 @@ +# %% [markdown] +# # Module 1 Practice 1 +# ## Getting started with Python in Jupyter Notebooks +# ### notebooks, comments, print(), type(), addition, errors and art +# +# Student will be able to +# - use Python 3 in Jupyter notebooks +# - write working code using `print()` and `#` comments +# - write working code using `type()` and variables +# - combine strings using string addition (+) +# - add numbers in code (+) +# - troubleshoot errors +# - create character art +# +# #   +# >**note:** the **[ ]** indicates student has a task to complete +# +# >**reminder:** to run code and save changes: student should upload or clone a copy of notebooks +# +# #### notebook use +# - [ ] insert a **code cell** below +# - [ ] enter the following Python code, including the comment: +# ```python +# # [ ] print 'Hello!' and remember to save notebook! +# print('Hello!') +# ``` +# Then run the code - the output should be: +# `Hello!` + +# %% +# [ ] print 'Hello' and remember to save notebook! +print('Hello!') + +# %% [markdown] +# #### run the cell below +# - [ ] use **Ctrl + Enter** +# - [ ] use **Shift + Enter** + +# %% +print('watch for the cat') + +# %% [markdown] +# #### Christina's Notebook editing +# - [ ] Edit **this** notebook Markdown cell replacing the word "Student's" above with your name +# - [ ] Run the cell to display the formatted text +# - [ ] Run any 'markdown' cells that are in edit mode, so they are easier to read + +# %% +#### [ ] convert \*this\* cell from markdown to a code cell, then run it +print('Run as a code cell') + + +# %% [markdown] +# ## # comments +# create a code comment that identifies this notebook, containing your name and the date + +# %% +# Christina Timokhin +# 02/05/2022 + +# %% [markdown] +# #### use print() to +# - [ ] print [**your_name**] +# - [ ] print **is using python!** + +# %% +# [ ] print your name +print("Christina Timokhin") +# [ ] print "is using Python" +print("is using Python!") + + +# %% [markdown] +# Output above should be: +# `Your Name +# is using Python!` + +# %% [markdown] +# #### use variables in print() +# - [ ] create a variable **your_name** and assign it a string containing your name +# - [ ] print **your_name** + +# %% +# [ ] create a variable your_name and assign it a sting containing your name +christina_timokhin = "Christina Timokhin" +#[ ] print your_name +print(christina_timokhin) + + +# %% [markdown] +# #### create more string variables +# - **[ ]** create variables as directed below +# - **[ ]** print the variables + +# %% +# [ ] create variables and assign values for: favorite_song, shoe_size, lucky_number +favorite_song = "Easy on Me" +shoe_size = "8" +lucky_number = "100" +# [ ] print the value of each variable favorite_song, shoe_size, and lucky_number +print(favorite_song) +print(shoe_size) +print(lucky_number) + + + +# %% [markdown] +# #### use string addition +# - **[ ]** print the above string variables (favorite_song, shoe_size, lucky_number) combined with a description by using **string addition** +# >for example favorite_song displayed as: +# `favorite song is happy birthday` + +# %% +# [ ] print favorite_song with description +favorite_song = "Easy on Me" +print("favorite song is " + favorite_song) +# [ ] print shoe_size with description +shoe_size = "8" +print("shoe size is " + shoe_size) +# [ ] print lucky_number with description +lucky_number = "100" +print("lucky number is " + lucky_number) + + +# %% + + +# %% [markdown] +# ##### more string addition +# - **[ ]** make a single string (sentence) in a variable called favorite_lucky_shoe using **string addition** with favorite_song, shoe_size, lucky_number variables and other strings as needed +# - **[ ]** print the value of the favorite_lucky_shoe variable string +# > sample output: +# `For singing happy birthday 8.5 times, you will be fined $25` + +# %% +# assign favorite_lucky_shoe using +print("My friend was singing " + favorite_song +" "+ shoe_size + " times " + "with " + lucky_number + " listeners") + + + +# %% [markdown] +# ### print() art + +# %% [markdown] +# #### use `print()` and the asterisk **\*** to create the following shapes +# - [ ] diagonal line +# - [ ] rectangle +# - [ ] smiley face + +# %% +# [ ] print a diagonal using "*" +print(" *") +print(" *") +print(" *") +print(" *") +print("*") + +# [ ] rectangle using "*" +print("****************") +print("* *") +print("* *") +print("****************") + +# [ ] smiley using "*" +print("** **") +print(" * ") +print("* *") +print(" * *") +print(" ******") + + + +# %% [markdown] +# #### Using `type()` +# -**[ ]** calulate the *type* using `type()` + +# %% +# [ ] display the type of 'your name' (use single quotes) +type('Christina Timokhin') + + + +# %% +# [ ] display the type of "save your notebook!" (use double quotes) +type("save your notebook") + + + +# %% +# [ ] display the type of "25" (use quotes) +type("25") + + + +# %% +# [ ] display the type of "save your notebook " + 'your name' +type("save your notebook " + 'Christina Timokhin ') + + + +# %% +# [ ] display the type of 25 (no quotes) +type(25) + + + +# %% +# [ ] display the type of 25 + 10 +type(25 + 10) + + + +# %% +# [ ] display the type of 1.55 +type(1.55) + + + +# %% +# [ ] display the type of 1.55 + 25 +type(1.55 + 25) + + + +# %% [markdown] +# #### Find the type of variables +# - **[ ]** run the cell below to make the variables available to be used in other code +# - **[ ]** display the data type as directed in the cells that follow + +# %% +# assignments ***RUN THIS CELL*** before starting the section + +student_name = "Gus" +student_age = 16 +student_grade = 3.5 +student_id = "ABC-000-000" + + +# %% +# [ ] display the current type of the variable student_name +type(student_name) + + + +# %% +# [ ] display the type of student_age +type(student_age) + + + +# %% +# [ ] display the type of student_grade +type(student_grade) + + + +# %% +# [ ] display the type of student_age + student_grade +type(student_age + student_grade) + + + +# %% +# [ ] display the current type of student_id +type(student_id) + + + +# %% +# assign new value to student_id +student_id = 888 + +# [ ] display the current of student_id +type(student_id) + + + +# %% [markdown] +# #### number integer addition +# +# - **[ ]** create variables (x, y, z) with integer values + +# %% +# [ ] create integer variables (x, y, z) and assign them 1-3 digit integers (no decimals - no quotes) +x = 2 +y = 3 +z = 4 + +# %% [markdown] +# - **[ ]** insert a **code cell** below +# - **[ ]** create an integer variable named **xyz_sum** equal to the sum of x, y, and z +# - **[ ]** print the value of **xyz_sum** + +# %% +xyz_sum = x + y + z +print(xyz_sum) + +# %% [markdown] +# ### Errors +# - **[ ]** troubleshoot and fix the errors below + +# %% +# [ ] fix the error +#print("Hello World!"") +print("Hello World!") + + +# %% +# [ ] fix the error +#print(strings have quotes and variables have names) +print("strings have quotes and variables have names") + + +# %% +# [ ] fix the error +print("I have $" + '5') + + + +# %% +# [ ] fix the error +print("always save the notebook") + + +# %% [markdown] +# ## ASCII art +# - **[ ]** Display first name or initials as ASCII Art +# - **[ ]** Challenge: insert an additional code cell to make an ASCII picture + +# %% +# [ ] ASCII ART +print(" ****** ********* ") +print(" ** *") +print(" ** *") +print(" ** *") +print(" ****** *") + + + +# %% +# [ ] ASCII ART +print(" O") +print(" /|\\") +print(" |") +print(" / \ ") + + + +# %% [markdown] +# # Module 1 Practice 2 +# ## Strings: input, testing, formatting +# Student will be able to +# - gather, store and use string `input()` +# - format `print()` output +# - test string characteristics +# - format string output +# - search for a string in a string + +# %% [markdown] +# ## input() +# getting input from users + +# %% +# [ ] get user input for a variable named remind_me +print("Enter reminder:") +remind_me = input() +# [ ] print the value of the variable remind_me +print("Reminder is " + remind_me) + +# %% +# [ ] print the value of the variable remind_me +print("Reminder is " + remind_me) + +# %% +# use string addition to print "remember: " before the remind_me input string +print("remember: " + remind_me) + + +# %% [markdown] +# ### Program: Meeting Details +# #### [ ] get user **input** for meeting subject and time +# `what is the meeting subject?: plan for graduation` +# `what is the meeting time?: 3:00 PM on Monday` +# +# #### [ ] print **output** with descriptive labels +# `Meeting Subject: plan for graduation` +# `Meeting Time: 3:00 PM on Monday` + +# %% +# [ ] get user input for 2 variables: meeting_subject and meeting_time +meeting_subject = input("what is the meeting subject?") +meeting_time = input("what is the meeting time?") +# [ ] use string addition to print meeting subject and time with labels +print("meeting subject:",meeting_subject) +print("meeting time:",meeting_time) + + + + +# %% [markdown] +# ## print() formatting +# ### combining multiple strings separated by commas in the print() function + +# %% +# [ ] print the combined strings "Wednesday is" and "in the middle of the week" +print("Wednesday is","in the middle of the week") + + +# %% +# [ ] print combined string "Remember to" and the string variable remind_me from input above +print("Remember to",remind_me) + + +# %% +# [ ] Combine 3 variables from above with multiple strings +print("reminder1:",remind_me,"and",meeting_subject,"at",meeting_time) + + +# %% [markdown] +# ### print() quotation marks + +# %% +# [ ] print a string sentence that will display an Apostrophe (') +print("She said she was 'funny'") + + + +# %% +# [ ] print a string sentence that will display a quote(") or quotes +print('She said it was "funny"') + + +# %% [markdown] +# ## Boolean string tests + +# %% [markdown] +# ### Vehicle tests +# #### get user input for a variable named vehicle +# print the following tests results +# - check True or False if vehicle is All alphabetical characters using .isalpha() +# - check True or False if vehicle is only All alphabetical & numeric characters +# - check True or False if vehicle is Capitalized (first letter only) +# - check True or False if vehicle is All lowercase +# - **bonus** print description for each test (e.g.- `"All Alpha: True"`) + +# %% +# [ ] complete vehicle tests +vehicle = input("What car do you drive?") +print("you car is",vehicle) +print("Is alpha?",vehicle.isalpha()) +print("Is alpha numeric?",vehicle.isalnum()) +print("Is first letter Capitilized?",vehicle.istitle()) +print("Is it lower case?",vehicle.islower()) + + + +# %% +# [ ] print True or False if color starts with "b" +color = input("What color is my car?") +print("you car color is",color) +print('does the color start with "b"?',color.startswith("b")) + +# %% [markdown] +# ## Sting formatting + +# %% +# [ ] print the string variable capital_this Capitalizing only the first letter +capitalize_this = "the TIME is Noon." +print(capitalize_this.capitalize()) + + +# %% +# print the string variable swap_this in swapped case +swap_this = "wHO writes LIKE tHIS?" +print(swap_this.swapcase()) + + +# %% +# print the string variable whisper_this in all lowercase +whisper_this = "Can you hear me?" +print(whisper_this.lower()) + + +# %% +# print the string variable yell_this in all UPPERCASE +yell_this = "Can you hear me Now!?" +print(yell_this.upper()) + + +# %% +#format input using .upper(), .lower(), .swapcase, .capitalize() +word = input('enter any word: ') +print("you entered a word:",word) +print("upper:",word.upper()) +print("lower:",word.lower()) +print("swapcase:",word.swapcase()) +print("captial:",word.capitalize()) + +# %% [markdown] +# ### input() formatting + +# %% +# [ ] get user input for a variable named color +# [ ] modify color to be all lowercase and print +color = input("enter color") +print("entered color",color) +print("lowercase:",color.lower()) + +# %% +# [ ] get user input using variable remind_me and format to all **lowercase** and print +# [ ] test using input with mixed upper and lower cases +remind_me = input("enter reminder") +print("entered reminder",remind_me) +print("lowercase:",remind_me.lower()) + + +# %% +# [] get user input for the variable yell_this and format as a "YELL" to ALL CAPS +yell_this = input("enter 'yell'") +print("uppercase:",yell_this.upper()) + + +# %% [markdown] +# ## "in" keyword +# ### boolean: short_str in long_str + +# %% +# [ ] get user input for the name of some animals in the variable animals_input +animals_input = input("enter the name of some animals") + +# [ ] print true or false if 'cat' is in the string variable animals_input +print('cat' in animals_input) + + +# %% +# [ ] get user input for color +color = input("enter the color") + +# [ ] print True or False for starts with "b" +print(color.startswith("b")) +# [ ] print color variable value exactly as input +# test with input: "Blue", "BLUE", "bLUE" +print(color) + + + + +# %% [markdown] +# ## Program: guess what I'm reading +# ### short_str in long_str +# +# 1. **[ ]** get user **`input`** for a single word describing something that can be read +# save in a variable called **can_read** +# e.g. - "website", "newspaper", "blog", "textbook" +#   +# 2. **[ ]** get user **`input`** for 3 things can be read +# save in a variable called **can_read_things** +#   +# +# 3. **[ ]** print **`true`** if the **can_read** string is found +# **in** the **can_read_things** string variable +# + +# %% +# project: "guess what I'm reading" + +# 1[ ] get 1 word input for can_read variable +can_read = input("enter 1 word") + +# 2[ ] get 3 things input for can_read_things variable +can_read_things = input("enter 3 things") + +# 3[ ] print True if can_read is in can_read_things +print(can_read in can_read_things) + +# [] challenge: format the output to read "item found = True" (or false) +# hint: look print formatting exercises +print("item found = ",can_read in can_read_things) + + +# %% [markdown] +# ## Program: Allergy Check +# +# 1. **[ ]** get user **`input`** for categories of food eaten in the last 24 hours +# save in a variable called **input_test** +# +# 2. **[ ]** print **`True`** if "dairy" is in the **input_test** string +# 3. **[ ]** Test the code so far +# 4. **[ ]** repeat the process checking the input for "nuts", **challenge** add "Seafood" and "chocolate" +# 5. **[ ]** Test your code +# +# 6. **[ ] challenge:** make your code work for input regardless of case, e.g. - print **`True`** for "Nuts", "NuTs", "NUTS" or "nuts" +# + +# %% +# Allergy check +# 1[ ] get input for test +input_test = input("enter food categories") + +# 2/3[ ] print True if "dairy" is in the input or False if not +print("Dairy:","dairy" in input_test) + +# 4[ ] Check if "nuts" are in the input +print("Nuts:","nuts" in input_test) +# 4+[ ] Challenge: Check if "seafood" is in the input +print("Seafood:","seafood" in input_test) +# 4+[ ] Challenge: Check if "chocolate" is in the input +print("Chocolate:","chocolate" in input_test) + +#cheese egg nuts candy sugar + +# %% [markdown] +# [Terms of use](http://go.microsoft.com/fwlink/?LinkID=206977)   [Privacy & cookies](https://go.microsoft.com/fwlink/?LinkId=521839)   © 2017 Microsoft + + diff --git a/Python Absolute Beginner/P1M2ChristinaTimokhin.py b/Python Absolute Beginner/P1M2ChristinaTimokhin.py new file mode 100644 index 0000000..4e30080 --- /dev/null +++ b/Python Absolute Beginner/P1M2ChristinaTimokhin.py @@ -0,0 +1,94 @@ +# %% [markdown] +# # Module 2 Practice +# ## Functions Arguments & Parameters +# Student will be able to +# - **create functions with a parameter** +# - **create functions with a `return` value** +# - **create functions with multiple parameters** +# - **use knowledge of sequence in coding tasks** +# - **use coding best practices** + +# %% [markdown] +# ##   +# Tasks + +# %% +# [ ] define and call a function short_rhyme() that prints a 2 line rhyme +def short_ryme(): + print("Once I dive into these pages,") + print("I may not come out for ages.") +short_ryme() + +# %% +# [ ] define (def) a simple function: title_it() and call the function +# - has a string parameter: msg +# - prints msg in Title Case +def title_it(msg): + print(msg.title()) + +title_it(" my name is christinA ") + +# %% +# [ ] get user input with prompt "what is the title?" +# [ ] call title_it() using input for the string argument +user_input=input("what is the title?") +title_it(user_input) + +# %% +# [ ] define title_it_rtn() which returns a titled string instead of printing +# [ ] call title_it_rtn() using input for the string argumetnt and print the result +def title_it_rtn(msg): + return msg.title() + +user_input = input("what is the title?") +titled = title_it_rtn(user_input) +print(titled) + +# %% [markdown] +# ## Program: bookstore() +# create and test bookstore() +# - **bookstore() takes 2 string arguments: book & price** +# - **bookstore returns a string in sentence form** +# - **bookstore() should call title_it_rtn()** with book parameter +# - **gather input for book_entry and price_entry to use in calling bookstore()** +# - **print the return value of bookstore()** +# >example of output: **`Title: The Adventures Of Sherlock Holmes, costs $12.99`** + +# %% +# [ ] create, call and test bookstore() function +def bookstore(book, price): + return title_it_rtn(book) + ", costs " + price + +book_entry = input("what is the book title?") +price_entry = input("what is the book price?") +output = bookstore(book_entry, price_entry) +print("Title: " + output) + + +# %% [markdown] +# ### Fix the error + +# %% +def make_greeting(name, greeting = "Hello"): + return (greeting + " " + name + "!") + +# get name and greeting, send to make_greeting + +def get_name(): + name_entry = input("enter a name: ") + return name_entry + +def get_greeting(): + greeting_entry = input("enter a greeting: ") + return greeting_entry + +#moved make greeting and other function calls after their defintions +print(make_greeting(get_name(), get_greeting())) + + + +# %% [markdown] +# +# [Terms of use](http://go.microsoft.com/fwlink/?LinkID=206977)   [Privacy & cookies](https://go.microsoft.com/fwlink/?LinkId=521839)   © 2017 Microsoft + + diff --git a/Python Absolute Beginner/P1M2ChristinaTimokhin_short.py b/Python Absolute Beginner/P1M2ChristinaTimokhin_short.py new file mode 100644 index 0000000..24fc968 --- /dev/null +++ b/Python Absolute Beginner/P1M2ChristinaTimokhin_short.py @@ -0,0 +1,15 @@ +def make_greeting(name, greeting = "Hello"): + return (greeting + " " + name + "!") + +# get name and greeting, send to make_greeting + +def get_name(): + name_entry = input("enter a name: ") + return name_entry + +def get_greeting(): + greeting_entry = input("enter a greeting: ") + return greeting_entry + +#moved make greeting and other function calls after their defintions +print(make_greeting(get_name(), get_greeting())) \ No newline at end of file diff --git a/Python Absolute Beginner/P1M2Christina_Timokhin.py b/Python Absolute Beginner/P1M2Christina_Timokhin.py new file mode 100644 index 0000000..97eda8f --- /dev/null +++ b/Python Absolute Beginner/P1M2Christina_Timokhin.py @@ -0,0 +1,7 @@ +# [ ] create, call and test fishstore() function +def fishstore(fish,price): + return ("Fish Type: "+ fish + " costs $" + price) + +fish_entry=input('Enter fish type: ') +price_entry=input('Enter fish type price: ') +print (fishstore(fish_entry,price_entry)) \ No newline at end of file diff --git a/Python Absolute Beginner/P1M3Christina_Timokhin.py b/Python Absolute Beginner/P1M3Christina_Timokhin.py new file mode 100644 index 0000000..e4d6b9a --- /dev/null +++ b/Python Absolute Beginner/P1M3Christina_Timokhin.py @@ -0,0 +1,23 @@ +# [ ] create, call and test +min_order_weight = 12 +max_order_weight = 15 +price = 4 + +print("Cheese Order:") + +def cheese_order(): + order_amount = float(input("Enter cheese order weight (numeric value): " )) + + if order_amount < min_order_weight: + belowErr = str(order_amount) + " is below the minimum order amount" + return(belowErr) + elif order_amount > max_order_weight: + aboveErr = str(order_amount) + " is more than currently available stock" + return(aboveErr) + else: + total = order_amount * price + finalStr = str(order_amount) + " pounds cost $" + str(total) + return finalStr + +resultStr = cheese_order() +print(resultStr) \ No newline at end of file diff --git a/Python Absolute Beginner/P1M4Christina_Timokhin.py b/Python Absolute Beginner/P1M4Christina_Timokhin.py new file mode 100644 index 0000000..aba680a --- /dev/null +++ b/Python Absolute Beginner/P1M4Christina_Timokhin.py @@ -0,0 +1,26 @@ +# [ ] create, call and test the str_analysis() function +def str_analysis(input_string): + if input_string.isdigit(): # If input only includes numeric values. + inputInt = int(input_string) # Converts str to int + + if inputInt > 99: # Greater than 99 + return str(inputInt) + " is a big number." + else: # Less than than 99 + return str(inputInt) + " is a small number." + else: # If input is not a digit + if input_string.isalpha(): # Only alphabetic characters + return input_string + " is all alphabetic characters." + else: # Multiple character types + return input_string + " is all multiple character types." + +print("Testing the Code \n---") +while True: + user_input = input("Enter string for testing: ") + if user_input == "": + print("") + else: + print(str_analysis(user_input)) + break + + + diff --git a/Python Absolute Beginner/P1M5Christina_Timokhin.py b/Python Absolute Beginner/P1M5Christina_Timokhin.py new file mode 100644 index 0000000..5bf806c --- /dev/null +++ b/Python Absolute Beginner/P1M5Christina_Timokhin.py @@ -0,0 +1,41 @@ +# [ ] create, call and test the adding_report() function + +def adding_report(report): #define the `adding_report` function with one parameter `report` that will be a string with default of "T" + #report="T" + total=0 + items="book" + + #- inside the function build a forever loop (infinite while loop) and inside the loop complete the following + while True: + #- use a variable to gather input (integer or "Q") + variable=input("Input an integer to add to the total or \"Q\" to quit\n") + # check if the input string is a digit (integer) and if it is then do the below... + + if variable.isdigit(): + items=(items+"\n"+variable) + variable=int(variable) + + total=total+variable #add input iteger (NOT STRING) to total + #if report type is "A" add the number characters to the item string seperated by a new line! Do not forget the new line! + elif variable=="Q": + if report=="A": + print("Items") + print(items) + print ("Total: \n ", total) + if report=="T": + print ("TOTAL: ", total) + break + else: + print("input is invalid") + + #Do the while True belo0w then print the answer and run it +while True: + + intrada=input("enter \'A\' for complete report, or \"T\" just for the total report") + if intrada=="A" or intrada=="T": + break + else: + print("error, A or T") + + +adding_report(intrada) \ No newline at end of file diff --git a/Python Fundamentals/P2M1_Christina_Timokhin.py b/Python Fundamentals/P2M1_Christina_Timokhin.py new file mode 100644 index 0000000..98fcf34 --- /dev/null +++ b/Python Fundamentals/P2M1_Christina_Timokhin.py @@ -0,0 +1,27 @@ +# [] create words after "G" following the Assignment requirements use of functions, menhods and kwyowrds +# sample quote "Wheresoever you go, go with all your heart" ~ Confucius (551 BC - 479 BC) +# [] copy and paste in edX assignment page +quote = input("enter a 1 sentence quote, non-alpha separate words: ") + +word = "" +position = 0 +end = len(quote) + +while position <= end: + if position == end and word[0] >= 'h': + print(word.upper()) + + break + + letter = quote[position] + + if letter.isalpha(): + word += letter.lower() + + elif len(word) > 0 and word[0] >= 'h': + print(word.upper()) + word = "" + else: + word = "" + + position += 1 \ No newline at end of file diff --git a/Python Fundamentals/P2M2_Christina_Timokhin.py b/Python Fundamentals/P2M2_Christina_Timokhin.py new file mode 100644 index 0000000..b0a950f --- /dev/null +++ b/Python Fundamentals/P2M2_Christina_Timokhin.py @@ -0,0 +1,23 @@ +# [] create list-o-matic +# [] copy and paste in edX assignment page +def list_o_matic(input_string, input_list): + if input_string == "": + return print(input_list.pop(), "popped from list") + else: + if input_string in input_list: + input_list.remove(input_string) + return print(input_string, "removed from list") + + else: + input_list.append(input_string) + return print("1 instance of", input_string, "appended to list") + + +check_list = ['cat', 'goat', 'chicken', 'horse'] + +while check_list: + check_string = input("enter the name of an animal or Quit for quit:") + if check_string.lower() == "quit": + break + else: + list_o_matic(check_string, check_list) diff --git a/Python Fundamentals/P2M3_ChristinaTimokhin.py b/Python Fundamentals/P2M3_ChristinaTimokhin.py new file mode 100644 index 0000000..0448241 --- /dev/null +++ b/Python Fundamentals/P2M3_ChristinaTimokhin.py @@ -0,0 +1,21 @@ +# [] create poem mixer +# [] copy and paste in edX assignment page +def word_mixer(word_list): + word_list.sort() + new_words = [] + while len(word_list)>5: + new_words.append(word_list.pop(-5)) + new_words.append(word_list.pop(0)) + new_words.append(word_list.pop()) + else: + return new_words + +str_value = input("enter a sentence: ") +words_list = str_value.split() #add len after +length = len(words_list) #add range after +for index in range(0, length): + if len(words_list[index])<=3: + words_list[index] = words_list[index].lower() + elif len(words_list[index])>=7: + words_list[index] = words_list[index].upper() +print(" ".join(word_mixer(words_list))) \ No newline at end of file diff --git a/Python Fundamentals/P2M4_Christina_Timokhin.py b/Python Fundamentals/P2M4_Christina_Timokhin.py new file mode 100644 index 0000000..a487f29 --- /dev/null +++ b/Python Fundamentals/P2M4_Christina_Timokhin.py @@ -0,0 +1,16 @@ +#!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt +mean_temp_file = open('/Users/cnt2019/mean_temp.txt', 'a+') +mean_temp_file.write("Rio de Janeiro,Brazil,30.0,18.0") +mean_temp_file.seek(0) +headings = mean_temp_file.readline() +headingsArr = headings.split(',') + +city_tempsArr = mean_temp_file.readlines() + +for tempLine in city_tempsArr: + city_temps = tempLine.split(',') + print(headingsArr[0] + " of " + city_temps[0] + " " + + headingsArr[2] + " is " + city_temps[2] + " Celsius") + + +#test \ No newline at end of file diff --git a/Python Fundamentals/P2M5_ChristinaTimokhin.py b/Python Fundamentals/P2M5_ChristinaTimokhin.py new file mode 100644 index 0000000..4b85b02 --- /dev/null +++ b/Python Fundamentals/P2M5_ChristinaTimokhin.py @@ -0,0 +1,41 @@ +correctNames = [] +incorrectNames = [] + +def get_names(): + #get_ipython().system(u' curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/elements1_20.txt -o elementsl_20.txt') + + # get 5 guesses from the user + print("list any 5 of the first 20 elements in the Period table: ") + + elements_file = open('/Users/cnt2019/elementsl_20.txt', 'r') + all_elements = elements_file.readlines() + + first5 = all_elements[0:5] + + first5 = [x.lower().strip() for x in first5] + + count = 0 + scores = [] + + while count < 5: + guess = input("Enter the name of an element: ").lower().strip() + if (guess in correctNames) | (guess in incorrectNames): + print(guess, " was already entered. <--- ") + else: + count += 1 + + if guess in first5: + scores.append("p") + correctNames.append(guess) + else: + scores.append("f") + incorrectNames.append(guess) + + return scores + + +collectedScores = get_names() +passCount = collectedScores.count("p") +print((passCount * 20), "% correct") +print("Found:", correctNames) +print("Not Found: ", incorrectNames) \ No newline at end of file diff --git a/Python Fundamentals/elements1_20.txt b/Python Fundamentals/elements1_20.txt new file mode 100644 index 0000000..4748f17 --- /dev/null +++ b/Python Fundamentals/elements1_20.txt @@ -0,0 +1,20 @@ +Hydrogen +Helium +Lithium +Beryllium +Boron +Carbon +Nitrogen +Oxygen +Fluorine +Neon +Sodium +Magnesium +Aluminum +Silicon +Phosphorus +Sulfur +Chlorine +Argon +Potassium +Calcium \ No newline at end of file diff --git a/Python Fundamentals/elementsl_20.txt b/Python Fundamentals/elementsl_20.txt new file mode 100644 index 0000000..4748f17 --- /dev/null +++ b/Python Fundamentals/elementsl_20.txt @@ -0,0 +1,20 @@ +Hydrogen +Helium +Lithium +Beryllium +Boron +Carbon +Nitrogen +Oxygen +Fluorine +Neon +Sodium +Magnesium +Aluminum +Silicon +Phosphorus +Sulfur +Chlorine +Argon +Potassium +Calcium \ No newline at end of file diff --git a/Python Fundamentals/mean_temp.txt b/Python Fundamentals/mean_temp.txt new file mode 100644 index 0000000..4198db6 --- /dev/null +++ b/Python Fundamentals/mean_temp.txt @@ -0,0 +1,10 @@ +city,country,month ave: highest high,month ave: lowest low +Beijing,China,30.9,-8.4 +Cairo,Egypt,34.7,1.2 +London,UK,23.5,2.1 +Nairobi,Kenya,26.3,10.5 +New York City,USA,28.9,-2.8 +Sydney,Australia,26.5,8.7 +Tokyo,Japan,30.8,0.9 + +Rio de Janeiro,Brazil,30.0,18.0 \ No newline at end of file diff --git a/Python Fundamentals/pi.txt b/Python Fundamentals/pi.txt new file mode 100644 index 0000000..8577145 --- /dev/null +++ b/Python Fundamentals/pi.txt @@ -0,0 +1 @@ +3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273 diff --git a/Python Fundamentals/rainbow.txt b/Python Fundamentals/rainbow.txt new file mode 100644 index 0000000..26ec8e7 --- /dev/null +++ b/Python Fundamentals/rainbow.txt @@ -0,0 +1,7 @@ +red +orange +yellow +green +blue +indigo +violet diff --git a/README.md b/README.md index 072e05c..92e0ddb 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,5 @@ The projects included here include working code and some experimental code. Some > This project requires that you install the flask module. After that, when you run it, it will create a web server on your machine and host your Python and HTML files in dynamic web pages. 7. Data Analytics with Jupyter and Pandas > COMING SOON +8. Christina Timokhin Test +> This project requires me to use VSCO code