Piyush Bhopalka and Saksham Agarwal
Press 'F' for FullscreenThe many-faced God has chosen to use python
Follow me to become no-one
Open gedit and type
print "A girl is ready!"
Save the file as noone.py
In your terminal, type
user:~$ python filename.py
print "Believe in the Many-faced God"
face = input()
face_count = 5
name = "noone"
face_count += 1
print face, face_count
Try them!! Take around 7 and a half minutes :)
Conditional Statements
if <condition 1>:
statement 1
statement 2
....
Pay special attention to indentation and the colon (:) symbol
Conditional Statements
Enhancing the if-conditions
if <condition 1>:
statement 1
statement 2
....
elif <condition 2>:
statement 3
statement 4
else:
statement 5
....
Pay special attention to indentation and the colon (:) symbol
We give you one name out of - Tyrion, Arya, Daenerys
You tell me their house
Sample Input (Take name as input):
Tyrion
John Snow
Sample Output (Print the house):
Lannister
You know nothing
Don't go to the next slide before you try this question !!
Hope you tried it yourself first :P
name = raw_input()
if name == "Tyrion":
print "Lannister"
elif name == "Arya":
print "Stark"
elif name == "Daenerys":
print "Targaryen"
else:
print "You know nothing"
Dont forget the indentation and colon (:) where required
Looping statements
while <condition>:
statement 1
statement 2
....
Pay special attention to indentation and the colon (:) symbol
Input a number from the user. Then, take n such numbers using the while loop and give me their sum
Sample Input:
5
2
2
2
3
3
Sample Output:
12
We will try this for another 7 and a half minutes :P
Gifts from the many-faced Gods - Inbuilt functions.
Let's learn how to use them :)
Functions help us stand on the shoulders of giants!
import math
pi = math.pi
a = math.sin(pi/2)
print a
This is a list. It is bound by square brackets []
kill_list = ["Joffrey", "Cersei", "Illyn Payne", "The Mountain"]
This is a tuple. It is bound by round brackets ()
family = ("Sansa", "Jon Snow")
Once created, contents of tuples cannot be changed. For a list, we can modify.
for loop
#Lets remove those names from her kill list
for i in kill_list:
print i, "is killed."
Pay special attention to indentation and the colon (:)
dict = {'Name': 'Arya', 'Age': 15, 'House': 'Stark'}
print "dict['Name']: ", dict['Name']
print "dict['Age']: ", dict['Age']
Download Geckodriver from here for Linux 64 bit.
sudo pip install selenium
export PATH=$PATH:/home/user/Downloads/
Download Chrome driver from here for Linux 64 bit.
cd Downloads
unzip chromedriver_linux64.zip
Browserium Launcharea
Open python in terminal and write the following code
from selenium import webdriver
browser = webdriver.Firefox()
Open python in terminal and write the following code
from selenium import webdriver
browser = webdriver.Chrome("./chromedriver")
browser.maximize_window()
browser.get("http://web.telegram.org")
find_element_by_id
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector
find_elements_by_id
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector
phone = browser.find_element_by_class_name
("login_phone_num_input_group")
phone.send_keys("9567035202\n")
Let's see if you can pass the OWL
OWL: Ordinary Wizarding Level
inputs_list = browser.find_elements_by_tag_name("input")
for i in inputs_list:
if "Search" in i.get_attribute("placeholder"):
search_input = i
break
search_input.click()
search_input.send_keys("Saksham")
text_box = browser.find_element_by_css_selector
("div.composer_rich_textarea")
text_box.send_keys("Hi, this is Piyush\n")
text_box = browser.find_element_by_css_selector
("div.composer_rich_textarea")
for i in range(10):
text_box.send_keys("Hi, this is Piyush\n")
try:
statement(s)
except ExceptionType as e: #'as e' is optional
statement(s)
For the Hufflepuffs amongst you...
Implicit Waits
driver.implicitly_wait(10) #seconds
You can have some other value than 10 also :P
Explicit Waits
#Long Live Irma Pince
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeOutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
delay = 10
try:
WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.CLASS_NAME, 'composer_rich_textarea')))
except TimeOutException:
#handle the case when element is not found
You learnt magic!
Now you have your own Patronus Charm
Irma Pince knows it all :P
We used the awesome framework called 'reveal.js'
You can too :)