Skip to content

Commit d80f183

Browse files
committed
initial commit
0 parents  commit d80f183

File tree

7 files changed

+216
-0
lines changed

7 files changed

+216
-0
lines changed

conditionalstatements.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import qrcode
2+
num = int(input("enter num"))
3+
print(f"you entered {num}")
4+
if (num > 0):
5+
{
6+
print("num is positive")
7+
}
8+
elif (num < 0):
9+
{
10+
print("num is negative")
11+
}
12+
else:
13+
{
14+
15+
print("num is zero")
16+
17+
}

datastructures/lists.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# A list is an ordered, mutable(changeable) collection of elements in Python. Lists can store any type of data(numbers, strings, other lists, etc.).
2+
3+
# list is a datatype which contains heterogenous data
4+
numbers = [1, 2, 3, 4, 5]
5+
for i in numbers:
6+
print(i, end=" ")
7+
print()
8+
9+
info = ['rohit', 21, '22BCS13677']
10+
for i in info:
11+
print(i, end=" ")
12+
print()
13+
14+
empty_list = []
15+
16+
# accessing list
17+
fruits = ["apple", "mango", 'banana', "guava", "cherry"]
18+
print(fruits[0])
19+
print(fruits[0:2]) # slice
20+
print(fruits[-1]) # last element
21+
22+
# replacing
23+
fruits[1] = "watermelon"
24+
print(fruits[1])
25+
26+
# adding
27+
fruits.append("melon") # adds in end
28+
print(fruits)
29+
fruits.insert(2, "tomato")
30+
print(fruits)
31+
32+
# removing
33+
fruits.remove("tomato") # remove specific element
34+
print(fruits)
35+
fruits.pop() # remove last element
36+
print(fruits)
37+
38+
# Create a list of 5 numbers and print their total_sum.
39+
num = [1, 2, 3, 4, 5]
40+
total_sum = 0
41+
for i in num:
42+
total_sum = total_sum+i
43+
print(total_sum)
44+
# Reverse a list without using[::-1].
45+
46+
while fruits:
47+
fruit = fruits.pop()
48+
empty_list.append(fruit)
49+
print(empty_list)

functions.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
def greet():
2+
print("hello")
3+
4+
5+
greet()
6+
7+
# with argument
8+
9+
10+
def Name(name):
11+
print(f"{name}")
12+
13+
14+
Name("rohit")
15+
16+
# with return
17+
18+
19+
def add(a, b):
20+
return a+b
21+
22+
23+
print(add(10, 20))
24+
25+
# default parameter
26+
27+
28+
def greet(name="Guest"):
29+
print(f"Hello, {name}!")
30+
31+
32+
greet() # Uses default: "Guest"
33+
greet("Rohit") # Uses "Rohit"
34+
35+
36+
# lambda function
37+
def square(x): return x*x
38+
39+
40+
print(square(4))
41+
# cube = lambda y: y*y*y
42+
# print(cube(4))
43+
44+
# Write a function multiply(a, b) that returns the product of two numbers.
45+
46+
47+
def multiply(a, b): return a*b
48+
49+
50+
print(multiply(5, 6))
51+
52+
# Write a function is_even(n) that returns True if a number is even, otherwise False.
53+
54+
55+
def is_even(num):
56+
return num % 2 == 0
57+
58+
59+
print(is_even(5))
60+
print(is_even(4))

generate_qrcode.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import qrcode
2+
qr = qrcode.make("https://www.youtube.com")
3+
qr.show()

hello.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# initialising variable
2+
# case sensitive language
3+
x = 12
4+
y = 30
5+
print(12+30)
6+
# using variables in expressions
7+
a = 5
8+
b = 7
9+
c = 10
10+
print(a*b*c)
11+
# taking input from user
12+
name = input("Enter your name: ") # default input type is string
13+
age = int(input("Enter your age: "))
14+
weight = float(input("Enter your weight (kg): "))
15+
height = float(input("Enter your height (m): "))
16+
# print
17+
print("\nHello, {}! You are {} years old. If you weigh {} kg and stand {} meters tall.".format(
18+
name, age, weight, height))

loops.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
languages = ["python", "c++", "java", "html", "js"]
2+
3+
# for loop(definite loop)
4+
# without range
5+
for lang in languages:
6+
print(lang, end=" ")
7+
print()
8+
9+
# with range
10+
for i in range(1, 6):
11+
print(i, end=" ")
12+
print()
13+
for i in range(5):
14+
print(i, end=" ")
15+
print()
16+
17+
# here 1 is start, 10 is end and 2 is to add to every iterations until <10
18+
for i in range(1, 10, 2):
19+
print(i, end=" ")
20+
print()
21+
22+
23+
# while loop(indefinite loop)
24+
num = 1
25+
while num <= 5:
26+
print(num, end=" ")
27+
num += 1 # increases number to avoid infinite loop
28+
print()
29+
30+
31+
char = 'a'
32+
while char <= 'd':
33+
print(char, end=" ")
34+
char = chr(ord(char)+1)
35+
print()
36+
# continue and break: continue is used to skip that specific iteration and move to next, break is used to exit from the loop
37+
for i in range(1, 10):
38+
if i == 3:
39+
continue
40+
print(i, end=" ")
41+
print()
42+
for i in range(1, 10):
43+
if i == 3:
44+
break
45+
print(i, end=" ")
46+
print()
47+
48+
# Write a Python program to print all even numbers from 1 to 20 using a for loop.
49+
for i in range(1, 10):
50+
if i % 2 == 0:
51+
print(i, end=" ")
52+
print()
53+
# Use a while loop to count down from 10 to 1.
54+
i = 10
55+
while i >= 1:
56+
print(i, end=" ")
57+
i -= 1
58+
print()
59+

print.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "rohit"
2+
age = 20
3+
print(f"my name is {name}, and my age is {age}")
4+
5+
height = "5'8"
6+
weight = 67.2
7+
print(f"my height is {height}, and my weight is {weight}")
8+
9+
programming_languages = ["cpp", "java", "JS", "python", "c#"]
10+
print(programming_languages[1])

0 commit comments

Comments
 (0)