Skip to content

Commit 736e244

Browse files
committed
Lecture 5 py web added
1 parent 979ed28 commit 736e244

22 files changed

+796
-0
lines changed

Lecture 5/Doubt Questions.ipynb

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import random"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 20,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"data": {
19+
"text/plain": [
20+
"0.28118881221259373"
21+
]
22+
},
23+
"execution_count": 20,
24+
"metadata": {},
25+
"output_type": "execute_result"
26+
}
27+
],
28+
"source": [
29+
"random.random()"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 28,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"outcomes = ['H', 'T']"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 49,
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"data": {
48+
"text/plain": [
49+
"['T', 'H', 'H', 'H', 'T']"
50+
]
51+
},
52+
"execution_count": 49,
53+
"metadata": {},
54+
"output_type": "execute_result"
55+
}
56+
],
57+
"source": [
58+
"random.choices(outcomes, weights=[3, 2], k = 5)"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 27,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"random.choices?"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 50,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"from collections import Counter"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 51,
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"Counter?"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 71,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"c = Counter(random.choices(outcomes, weights=[9, 2], k=15))"
95+
]
96+
},
97+
{
98+
"cell_type": "code",
99+
"execution_count": 72,
100+
"metadata": {},
101+
"outputs": [
102+
{
103+
"data": {
104+
"text/plain": [
105+
"13"
106+
]
107+
},
108+
"execution_count": 72,
109+
"metadata": {},
110+
"output_type": "execute_result"
111+
}
112+
],
113+
"source": [
114+
"c['H']"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": 70,
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"data": {
124+
"text/plain": [
125+
"6"
126+
]
127+
},
128+
"execution_count": 70,
129+
"metadata": {},
130+
"output_type": "execute_result"
131+
}
132+
],
133+
"source": [
134+
"c['T']"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 73,
140+
"metadata": {},
141+
"outputs": [
142+
{
143+
"data": {
144+
"text/plain": [
145+
"Counter({'H': 13, 'T': 2})"
146+
]
147+
},
148+
"execution_count": 73,
149+
"metadata": {},
150+
"output_type": "execute_result"
151+
}
152+
],
153+
"source": [
154+
"c"
155+
]
156+
},
157+
{
158+
"cell_type": "code",
159+
"execution_count": 62,
160+
"metadata": {},
161+
"outputs": [
162+
{
163+
"data": {
164+
"text/plain": [
165+
"[('H', 9)]"
166+
]
167+
},
168+
"execution_count": 62,
169+
"metadata": {},
170+
"output_type": "execute_result"
171+
}
172+
],
173+
"source": [
174+
"c.most_common(1)"
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"metadata": {},
181+
"outputs": [],
182+
"source": []
183+
}
184+
],
185+
"metadata": {
186+
"kernelspec": {
187+
"display_name": "Python 3",
188+
"language": "python",
189+
"name": "python3"
190+
},
191+
"language_info": {
192+
"codemirror_mode": {
193+
"name": "ipython",
194+
"version": 3
195+
},
196+
"file_extension": ".py",
197+
"mimetype": "text/x-python",
198+
"name": "python",
199+
"nbconvert_exporter": "python",
200+
"pygments_lexer": "ipython3",
201+
"version": "3.6.3"
202+
}
203+
},
204+
"nbformat": 4,
205+
"nbformat_minor": 2
206+
}

Lecture 5/PyWeb.ipynb

Lines changed: 527 additions & 0 deletions
Large diffs are not rendered by default.

Lecture 5/codechef.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from selenium import webdriver
2+
import getpass
3+
import time
4+
5+
# codechef credentials for login
6+
username = "nikhilksingh97"
7+
password = getpass.getpass("Password:")
8+
9+
# problem code
10+
problem = 'TEST'
11+
12+
# submission code
13+
code = """
14+
#include <iostream>
15+
16+
int main(void) {
17+
char c, d=10;
18+
while(std::cin.get(c) && (c!='2' || d!='4') && std::cout.put(d))
19+
d=c;
20+
}
21+
"""
22+
23+
# start a browser session
24+
browser = webdriver.Firefox()
25+
26+
# open link in browser
27+
browser.get('https://www.codechef.com')
28+
29+
# login
30+
nameElem = browser.find_element_by_id('edit-name')
31+
nameElem.send_keys(username)
32+
33+
passElem = browser.find_element_by_id('edit-pass')
34+
passElem.send_keys(password)
35+
36+
browser.find_element_by_id('edit-submit').click()
37+
38+
# open submission page
39+
browser.get("https://www.codechef.com/submit/" + problem)
40+
41+
# sleep function to let web components load in case of slow internet connnection
42+
time.sleep(10)
43+
44+
# click on toggle button to open simple text mode
45+
browser.find_element_by_id("edit_area_toggle_checkbox_edit-program").click()
46+
47+
# submit the code
48+
inputElem = browser.find_element_by_id('edit-program')
49+
inputElem.send_keys(code)
50+
51+
browser.find_element_by_id("edit-submit").click()
52+

Lecture 5/pictures/profile1.jpg

Lines changed: 1 addition & 0 deletions
Loading

Lecture 5/pictures/profile10.jpg

14.2 KB
Loading

Lecture 5/pictures/profile11.jpg

5.77 KB
Loading

Lecture 5/pictures/profile12.jpg

Lines changed: 1 addition & 0 deletions
Loading

Lecture 5/pictures/profile13.jpg

9.7 KB
Loading

Lecture 5/pictures/profile14.jpg

Lines changed: 1 addition & 0 deletions
Loading

Lecture 5/pictures/profile15.jpg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)