Skip to content

Commit 03e4267

Browse files
authored
Add files via upload
CampusX
0 parents  commit 03e4267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+11259
-0
lines changed

Python Basics/Basics/BreakContinue.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Break statement : terminates loop at a condition
2+
3+
for i in range (1,11):
4+
if i == 5:
5+
break
6+
print(i)
7+
8+
#Continue statement: skips code after continue for that particaular iteration or condition
9+
10+
for i in range(1,11):
11+
if i == 5:
12+
continue
13+
print(i, "hello")
14+
15+
#Pass statement: skips the loop, avoids error messages
16+
for i in range(1,11):
17+
pass
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import math
2+
3+
math.ceil(5.5)
4+
math.floor(6.9)
5+
math.sqrt(100)
6+
7+
import random
8+
9+
random.randint(1,100)
10+
a = [1,2,3,4,5,6]
11+
random.shuffle(a)
12+
print(a)
13+
14+
import time
15+
16+
time.time()
17+
18+
import os
19+
20+
os.getcwd()
21+
22+
os.listdir()

Python Basics/Basics/DataTypes.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# integer
2+
print(4)
3+
print(1e309)
4+
5+
#float
6+
print(1.7)
7+
print(1.7e308)
8+
9+
#boolean
10+
print(True)
11+
print(False)
12+
13+
#complex
14+
print(4+5j)
15+
16+
#string
17+
print('Sam')
18+
print("Sam")
19+
print("'Sam'")
20+
print("""Sam""")
21+
22+
23+
#lists
24+
print([1,2,3,4,5])
25+
26+
#tuple
27+
print((1,2,3,4,5))
28+
29+
#sets
30+
print({1,2,3,4,5})
31+
32+
#dict
33+
print({"Name": "Sam", "Age": 30, "gender": "Male"})

Python Basics/Basics/FirstProgram.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello World")

Python Basics/Basics/ForLoop.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
for i in range(1,11):
2+
print(i)
3+
4+
for i in "KOLKATA":
5+
print(i)
6+
7+
#so basically or loops operates on
8+
# range function or sequences: tuples,
9+
# sets, strings,
10+
11+
for i in [1,2,3,4,5,5,5]:
12+
print(i)

Python Basics/Basics/GuessingGame.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import random
2+
3+
jackpot = random.randint(1,100)
4+
5+
guess = int(input("Guess the number: "))
6+
Counter = 1
7+
8+
while guess != jackpot:
9+
if guess < jackpot:
10+
print("Guess Higher")
11+
else:
12+
print("Guess lower")
13+
14+
guess = int(input("Guess again: "))
15+
Counter += 1
16+
17+
18+
print("Correct Guess")
19+
print("You took", Counter, "attempts")

Python Basics/Basics/InputFunction.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
input("Your name ?")
2+
3+
first_num = input("Enter first number: ")
4+
second_num = input("Enter second number: ")
5+
6+
print(first_num)
7+
print(second_num)
8+
9+
result = int(first_num) + int(second_num)
10+
print(result)
11+
12+
# default format for input function: STRING
13+
#that's why numbers are literally adding, they;re being read as string
14+
15+
#type function: tells data type
16+
17+
print(type(first_num))
18+
19+
#TYPE_CONVERSION
20+
21+
a = int(4.5)
22+
print(type(a))
23+
24+
a = bool(4)
25+
print(type(a))
26+

Python Basics/Basics/NestedLoop.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rows = int(input("Enter the number of rows: "))
2+
3+
for i in range(1, rows +1):
4+
for j in range(0, i):
5+
print("*", end= " ")
6+
print("")

Python Basics/Basics/RangeFn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#range function
2+
range(1,100)
3+
print(list(range(1,11)))
4+
5+
print(list(range(1,11,2)))
6+
print(list(range(11,0,-2)))

Python Basics/Basics/Variable.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#C Lang
2+
#int a = 5
3+
4+
name = "Sam"
5+
print(name)
6+
7+
name = 'Sam'
8+
print(name)
9+
10+
#No Variable Declaration
11+
12+
# dynamic typing = not declaring data type also in PHP
13+
# static typing = specifying data type
14+
15+
name = "Hello World"
16+
print(name)
17+
18+
name = 4
19+
print(4)
20+
21+
name = True
22+
print(name)
23+
24+
#special syntax
25+
a = 4; b = 5; c= 6
26+
print(a)
27+
print(b)
28+
print(c)
29+
30+
a,b,c = 4,5,6
31+
print(a)
32+
print(b)
33+
print(c)
34+
35+
a=b=c=6
36+
print(a)
37+
print(b)
38+
print(c)

0 commit comments

Comments
 (0)