Skip to content

Commit 9325ea8

Browse files
adds day 1 codes
1 parent 9f11121 commit 9325ea8

22 files changed

+383
-0
lines changed

day-1/arithmetic-operations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Arithmetic operations
2+
a = float(input())
3+
b = float(input())
4+
5+
print(a + b)
6+
print(a - b)
7+
print(a * b)
8+
print(a / b)
9+
10+
# Integer division a / b --> int(a / b)
11+
print(a // b)
12+
# print(int(-10.9))
13+
14+
# Mod operator --> a - (a // b) * b
15+
print(a % b)
16+
17+
# power function (a^b)
18+
print(a ** b)

day-1/comments.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Comments
2+
# Single Line Comment
3+
# single line comment
4+
5+
"""
6+
Multiple Line Comments
7+
This is
8+
a
9+
big paragraph
10+
explaining the code
11+
"""
12+
13+
# Camel case (completely used in java/c++/C#/C and python)
14+
firstSecondThirdFourth = 10
15+
firstName = 'john'
16+
lastName = 'doe'
17+
randomWordGenerator = 10
18+
19+
# Snake case (heavily used in python)
20+
first_second_third_fourth = 100
21+
first_name = 'john'
22+
last_name = 'doe'
23+
24+
# Pascal Case (classes in java and C++ --> not used in python)
25+
FirstName = 'anish'
26+
LastName = 'sachdeva'
27+
28+
# Allowed Variables
29+
# asdasdsadas
30+
# i, j, k, l, m, m
31+
anish = 10
32+
# 23hy # not allowed
33+
_dfds = 90
34+
number3432423 = 100

day-1/even-odd.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
number = int(input())
2+
3+
if number % 2 == 0:
4+
print('number is even')
5+
else:
6+
print('number is odd')

day-1/factorial.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Factorial
3+
N! = 1 * 2 * 3 * ... * N
4+
N! = N * (N-1)!
5+
0! = 1
6+
"""
7+
8+
n = int(input())
9+
10+
acc = 1
11+
i = 1
12+
while i <= n:
13+
acc *= i # acc = acc * i
14+
i += 1 # i = i + 1
15+
16+
print(acc)
17+
18+
n = int(input())
19+
acc = 1
20+
for number in range(1, n + 1):
21+
acc *= number
22+
print(acc)

day-1/for-loops.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
For Loops
3+
for var in iterable_object:
4+
code
5+
code
6+
"""
7+
8+
for number in range(10, -1, -2):
9+
print(number)
10+
11+
n = int(input())
12+
acc = 1
13+
for number in range(1, n + 1):
14+
acc *= number
15+
print(acc)
16+
17+
for character in 'banana':
18+
print(character)

day-1/hello-world-loop.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
n = int(input())
2+
i = 0
3+
while i < n:
4+
print('hello world')
5+
i += 1

day-1/hello-world.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
print('hey there', end='####')
2+
print('hello', end='--')
3+
print('this')
4+
print('i am in next line', end='')

day-1/if-else-conditions.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
If else statements
3+
4+
if condition:
5+
code
6+
code
7+
code
8+
else: (not necessary)
9+
code
10+
code
11+
code
12+
13+
If condition: (compulsory)
14+
code
15+
code
16+
code
17+
elif condition2: (not compulsory)
18+
code
19+
code
20+
elif condition3:
21+
code
22+
code
23+
elif condition4:
24+
code
25+
code
26+
.
27+
.
28+
.
29+
30+
else: (not compulsory)
31+
code
32+
code
33+
"""
34+
35+
# if (condition) { sdfdsfsdf }
36+
37+
if False:
38+
print('i am in if block')
39+
print('yeah!!!!!!!!!!!!!')
40+
else:
41+
print('i am in else block')
42+
print(':(')
43+
44+
print('i am outside if else')

day-1/infinite-loop.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# i = 1
2+
# while True:
3+
# print('hello world : ' + str(i))
4+
# i += 1
5+
6+
hello = 'hello'
7+
iterable = hello.__iter__()
8+
print(type(iterable))
9+
10+
# print(iterable.__next__())
11+
# print(iterable.__next__())
12+
# print(iterable.__next__())
13+
# print(iterable.__next__())
14+
# print(iterable.__next__())
15+
# print(iterable.__next__())
16+
17+
iterable = hello.__iter__()
18+
while True:
19+
try:
20+
var = iterable.__next__()
21+
print(var)
22+
except:
23+
# print("An exception occurred")
24+
break

day-1/input.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
firstName = input()
2+
lastName = input() # leftName <-- input()
3+
4+
# print(firstName)
5+
# print(lastName)
6+
print(type(firstName))
7+
# string concatenation
8+
print(firstName + ' ' + lastName)

day-1/int-input.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
number = int(input())
2+
print(type(number))
3+
print(number)
4+
5+
6+
# taking float value
7+
# number = float(input())

day-1/largest-3-numbers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
a = int(input())
2+
b = int(input())
3+
c = int(input())
4+
5+
if a >= b and a >= c:
6+
print(a)
7+
elif b >= a and b >= c:
8+
print(b)
9+
else:
10+
print(c)

day-1/lists.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
List / Array
3+
Iterable
4+
"""
5+
6+
numbers = []
7+
print(type(numbers))
8+
9+
# adding elements
10+
# append adds at the last index (value)
11+
numbers.append(10)
12+
numbers.append(45)
13+
print(numbers)
14+
15+
# insert (index, value)
16+
numbers.insert(0, 45)
17+
print(numbers)
18+
19+
# remoing an element
20+
# pop (no arg) --> removes from last index
21+
# remove(value)
22+
# del keyword removes variable
23+
24+
# Sorting a list
25+
# list_name.sort()
26+
27+
# splicing
28+
# list[start : stop : step]
29+
# by default start = 0, stop = len(list), step = 1
30+
31+
# reversing a list
32+
# list[::-1]

day-1/logical-operators.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Boolean type
2+
var = False
3+
# print(type(var))
4+
5+
# print(True)
6+
# print(False)
7+
8+
# Or operator
9+
# print(False or False) # --> false
10+
# print(True or False) # true
11+
# print(False or True) # true
12+
# print(True or True) # true
13+
14+
# And operator
15+
# print(False and False) # false
16+
# print(True and False) # false
17+
# print(False and True) # false
18+
# print(True and True) # true
19+
20+
# equality operator
21+
print(2 == 2)
22+
23+
# comparison operator
24+
print(1 < 10)
25+
print(1 > 10)
26+
print(1 <= 5) # --> a < b or a == b
27+
print(-3 >= -5)
28+
29+
# is operator (==)
30+
print(7 is 7)
31+
32+
# not operator
33+
print(not True) # false
34+
print(not False) # true

day-1/loop-control-statements.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Break statement
2+
# for number in range(1, 10):
3+
# if number == 7:
4+
# break
5+
# print(number)
6+
7+
8+
# Continue Statement
9+
for number in range(1, 10):
10+
if number % 2 == 0:
11+
continue
12+
print(number)

day-1/nested-loop.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
for i in range(1, 5):
2+
for j in range(2, 6):
3+
print(str(i) + ' x ' + str(j) + ' = ' + str(i * j))

day-1/python-if-else.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
number = int(input())
2+
3+
if number % 2 == 1:
4+
print('Weird')
5+
elif 2 <= number <= 5: # --> number >= 2 and number <= 5 --> number == 2 or number == 4
6+
print('Not Weird')
7+
elif 6 <= number <= 20:# --> number >= 6 and number <= 20
8+
print('Weird')
9+
elif number > 20:
10+
print('Not Weird')

day-1/range-type.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Range
3+
range(stop)
4+
range(start, stop)
5+
range(start, stop, step)
6+
7+
default start = 0
8+
default step = 1
9+
"""
10+
11+
r = range(5, 10, 2)
12+
print(r.start)
13+
print(r.stop)
14+
print(r.step)
15+
print(type(r))

day-1/sum-of-n-numbers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
N
3+
1 + 2 + 3 + 4 + ... + N
4+
N (N + 1) / 2
5+
"""
6+
7+
n = int(input())
8+
acc = 0
9+
i = 1
10+
while i <= n:
11+
acc += i
12+
i += 1
13+
14+
print(acc)
15+
16+
n = int(input())
17+
acc = 1
18+
for number in range(1, n + 1):
19+
acc += number
20+
print(acc)

day-1/sum-of-squares.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
n = int(input())
2+
3+
i = 1
4+
acc = 0
5+
while i <= n:
6+
acc += i ** 2
7+
i += 1
8+
print(acc)

day-1/variables.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# string variables
2+
# string literal ('') ("")
3+
firstName = 'anish'
4+
lastName = "sachdeva"
5+
# print(type(firstName))
6+
# print(type(lastName))
7+
# var = input()
8+
# print(type(var))
9+
10+
# Integer
11+
# number = -45
12+
# print(type(number))
13+
# num2 = 1000
14+
# num3 = 765
15+
# print(type(num2))
16+
17+
# Floating Numbers
18+
# pi = 3.14
19+
# e = 2.71828
20+
# number = 10.0
21+
# print(type(pi))
22+
# print(type(e))
23+
# print(type(number))

0 commit comments

Comments
 (0)