Skip to content

Commit 7f0f62d

Browse files
committed
PythonBasics
0 parents  commit 7f0f62d

File tree

7 files changed

+172
-0
lines changed

7 files changed

+172
-0
lines changed

1.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# print("Hyy, This is mine 1st program in python")
2+
3+
# 1.variables
4+
5+
# name = "Ram"
6+
# age = 20
7+
# print(name)
8+
# print(age)
9+
10+
# 2.exercise
11+
12+
# firstName = "Tony"
13+
# lastName = "Stark"
14+
# age = 51
15+
# print(firstName+" "+lastName)
16+
# print (age)
17+
# isGenius = True
18+
# print(isGenius)
19+
20+
# 3.take input from user
21+
22+
name = input("What is your name")
23+
print(name)
24+
25+
# 4.exercise
26+
27+
ans = input("who is your superhero and why?")
28+
print(ans)

2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# oldAge = input("enter your old age: ")
2+
# newAge = int(oldAge) + 2 #float, char, bool
3+
# print(newAge)
4+
5+
# number = 18
6+
# print(float(number))
7+
8+
# first = input("enter the first number: ")
9+
# second = input("enter second nuber: ")
10+
# sum = int(first)+int(second)
11+
# print(sum) # print("The sum is: "+str(sum))
12+
13+
name = "Tony Stark"
14+
print(name.upper())
15+
print(name.lower()) # To lowerCase
16+
print(name.find('S')) # Searching of 'S' in the string
17+
print(name.find('s'))
18+
#"Tony Stark" replaced by "Ironman"
19+
print(name.replace("Tony Stark", "IronMan"))
20+
print('T' in name)
21+
print('c' in name)

3.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Operators
2+
3+
print(5+2) #sum
4+
print(5-2) #sub
5+
print(5/2) #devide
6+
print(5*2) #mul
7+
print(10//3) #to get only integer value
8+
print(5**2) #power
9+
print(10%3) #modulo operator to bget remainder
10+
11+
#Comparoson operator
12+
13+
print(3>2)
14+
print(3==3)
15+
print(3<2)
16+
# Logical operator
17+
print(2>3 or 2<1)
18+
print(2>3 and 3<2)
19+
print(not(2>3))
20+
21+
22+
age = 2
23+
if age>=18:
24+
print("you are adult")
25+
print("you can vote")
26+
elif age<18 and age>3:
27+
print("You're in school")
28+
else:
29+
print("You're a child")

4Calculator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
first = input("Enter first number: ")
2+
operator = input("Enter operator(+,-,*,/,%): ")
3+
second = input("Enter second number: ")
4+
\
5+
first = int(first)
6+
second = int(second)
7+
if operator == "+":
8+
print(first+second)
9+
elif operator == "-":
10+
print(first-second)
11+
elif operator=="*":
12+
print(first*second)
13+
elif operator == "/":
14+
print(first/second)
15+
else:
16+
print(first%second)

5Range.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
i = 1
2+
while(i<11):
3+
print(i*"*")
4+
i += 1
5+
6+
7+
for item in range(5):
8+
print(item+1)
9+
10+
# List - Collection of items
11+
12+
marks = [95, 98, 99]
13+
print(marks[2])
14+
print(marks[-2]) # - last se index dekhta hai
15+
print(marks[1:3]) # index 1 se 3 tak ke sare element, ending index is excluding
16+
17+
for score in marks:
18+
print(marks)
19+
marks.append(100)
20+
print(marks)
21+
22+
# to check a number is exist in list or not
23+
print(99 in marks)
24+
25+
# length of the list
26+
print(len(marks))
27+
28+
# to empty list
29+
marks.clear()
30+
print(marks)
31+

6.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 1.break
2+
3+
# students = ["Ram", "Shyam", "Kishan", "Radha", "Radhika"]
4+
# for student in students:
5+
# if student == "Radha":
6+
# break
7+
# print(student)
8+
9+
# 2.continue
10+
11+
# students = ["Ram", "Shyam", "Kishan", "Radha", "Radhika"]
12+
# for student in students:
13+
# if student == "Kishan":
14+
# continue
15+
# print(student)
16+
17+
# Conclusion - {} for sets, [] for lists, () for tuples
18+
19+
# 3.Tuples - immutable string
20+
21+
# marks = (95, 97, 98, 97)
22+
# print(marks.count(97))
23+
# print(marks.index(95))
24+
25+
# 4.sets - unorder sequence
26+
27+
# marks = {90, 92, 93, 96, 93, 95}
28+
# print(marks)
29+
30+
# 5.Dictionary
31+
32+
marks = {"English" : 95, "Mathematics" : 97, "Physics":100}
33+
print(marks["Mathematics"])
34+
marks["Science"] = 92
35+
print(marks)

7_Functions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#inbuilt function
2+
3+
# from math import *
4+
# print(sqrt(16))
5+
6+
# user defined function
7+
8+
def sum(a, b):
9+
print(a+b)
10+
11+
sum(2,3)
12+

0 commit comments

Comments
 (0)