Skip to content

Commit 4e980f2

Browse files
Introduction to Python
0 parents  commit 4e980f2

23 files changed

+251
-0
lines changed

2DListsAndNestedLoops.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
number_grid = [
2+
[1, 2, 3],
3+
[4, 5, 6],
4+
[7, 8, 9],
5+
[0]
6+
]
7+
8+
print(number_grid[0][0])
9+
print(number_grid[1][2])
10+
11+
for row in number_grid:
12+
for column in row:
13+
print(column)
14+
# print(row)

HelloWorld.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello World!")

advancedCalculator.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
num1 = float(input("Enter the first number: "))
2+
operation = input("Enter the operation: ")
3+
num2 = float(input("Enter the third number: "))
4+
5+
def calculator(num1, operation, num2):
6+
if operation == "+":
7+
return num1 + num2
8+
elif operation == "-":
9+
return num1 - num2
10+
elif operation == "*":
11+
return num1 * num2
12+
elif operation == "/":
13+
return num1 / num2
14+
else:
15+
return "Invalid operation"
16+
17+
print(calculator(num1, operation, num2))

basicCalc.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
num1 = input("Enter first number: ")
2+
num2 = input("Enter second number: ")
3+
result = float(num1) + float(num2)
4+
print(result)
5+

dictionaries.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
monthConversions = {
2+
"Jan": "January",
3+
"Feb": "February",
4+
"Mar": "March",
5+
"Apr": "April",
6+
"May": "May",
7+
"Jun": "June",
8+
"Jul": "July",
9+
"Aug": "August",
10+
"Sep": "September",
11+
"Oct": "October",
12+
"Nov": "November",
13+
"Dec": "December"
14+
}
15+
16+
print(monthConversions["Nov"])
17+
print(monthConversions.get("Dec"))
18+
print(monthConversions.get("Var")) # none
19+
print(monthConversions.get("Var", "Not found")) # Not found

drawAShape.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
print(" /|")
2+
print(" / |")
3+
print(" / |")
4+
print(" / |")
5+
print("/____|")

exponentFunctions.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def raise_to_power(base, exponent):
2+
result = 1
3+
for i in range(exponent):
4+
result *= base
5+
return result
6+
7+
print(raise_to_power(2, 3))

forLoop.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
for i in "Varshith Pabbisetty":
2+
print(str(i).upper())
3+
4+
friends = ["Ruthvik", "Shivam", "Ajay"]
5+
for i in friends:
6+
print(i)
7+
8+
print("")
9+
10+
for i in range(len(friends)):
11+
print(friends[i])
12+
13+
print("")
14+
15+
for index in range(3, 10):
16+
print(index)
17+
18+
print("")
19+
20+
for index in range(10):
21+
print(index)
22+
23+
print("")
24+
25+
for index in range(3, 10, 4):
26+
print(index)

functions.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def say_hi():
2+
print("Hello User")
3+
4+
def say_his(name, age):
5+
print("Hello " + name + ", you are " + str(age) + " years old")
6+
7+
8+
say_hi()
9+
10+
say_his("Vaishnavi", 22)
11+
say_his("Likitha", 21)

guessGame.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
secret_word = "zebra"
2+
guess = ""
3+
guess_count = 0
4+
guess_limit = 3
5+
out_of_guesses = False
6+
7+
while guess != secret_word and not(out_of_guesses):
8+
if guess_count < guess_limit:
9+
guess = str(input("Enter Guess:")).lower()
10+
guess_count += 1
11+
else:
12+
out_of_guesses = True
13+
14+
if out_of_guesses:
15+
print("You ran out of guesses!")
16+
else:
17+
print("You got it!")

ifStatements.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def main(a, b, c):
2+
if a >= b and a >= c:
3+
return "a is greater than b"
4+
elif b >= a and not(b <= c):
5+
return "b is greater than a"
6+
else:
7+
return "c is greater than a"
8+
9+
print(main(1, 2, 1))

inputFromUsers.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = input("Enter your name: ")
2+
age = input("Enter your age: ")
3+
4+
print("Hello " + name + "!" + " You are " + age + " years old.")

listFunctions.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
lucky_numbers = [17, 34, 81, 7, 56, 6]
2+
friends = ["Ruthvik", "Saikiran", "Pruthvi", "Varshith", "Harsha", "Sohan"]
3+
4+
# friends.extend(lucky_numbers)
5+
friends.append("Shankar")
6+
friends.insert(1, "Varshith")
7+
friends.remove("Shankar")
8+
friends.pop()
9+
print(friends.index("Pruthvi"))
10+
print(friends.count("Varshith"))
11+
friends.sort()
12+
lucky_numbers.sort()
13+
print(lucky_numbers)
14+
lucky_numbers.reverse()
15+
print(friends)
16+
friends2 = friends.copy()
17+
print(lucky_numbers)

lists.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
friends = ["Ruthvik", "Saikiran", "Pruthvi", "Harsha", "Sohan"]
2+
print(friends)
3+
print(friends[0])
4+
print(friends[1:])
5+
print(friends[-1])
6+
print(friends[1:3])

madLibsGame.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
color = input("Enter a color: ")
2+
plural_noun = input("Enter a plural noun: ")
3+
celebrity = input("Enter a celebrity: ")
4+
5+
print("Rosesquares are " + color)
6+
print(plural_noun + " are green")
7+
print("I love " + celebrity)

number.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from math import *
2+
3+
4+
print(2)
5+
print(2.98999)
6+
print(2.98999 + 0.00001)
7+
print(2.98999 - 0.00001)
8+
print(2.98999 * 2)
9+
print(2.98999 / 2)
10+
print(3 * 4 + 5)
11+
print(3 * (4 + 5))
12+
print(3 // 4) # division of a number
13+
print(3 % 4) # remainder of a division(modulus)
14+
15+
my_num = 5
16+
print(str(my_num) + " is my number") # string conversion
17+
print(pow(3, 2)) # power of a number
18+
print(max(4,6)) # maximum of two numbers
19+
print(min(4,6)) # minimum of two numbers
20+
print(round(3.6)) # round
21+
print(str(floor(3.6)) + " floor") # floor
22+
print(str(ceil(3.2)) + " ceil") # ceil
23+
print(str(sqrt(9)) + " sqrt") # square root
24+
print(str(exp(1)) + " exp") # exponential
25+
print(str(log(10)) + " log") # logarithm
26+
print(str(log10(10)) + " log base 10") # logarithm base 10
27+
print(str(log2(10)) + " log base 2") # logarithm base 2
28+
my_num = -6
29+
print(abs(my_num)) # absolute value of a number

returnStatement.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def add(a, b):
2+
return a + b
3+
4+
def cube(g) :
5+
return g * g * g
6+
7+
res = add(1, 7.6)
8+
print(res)
9+
print(cube(2))

strings.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
print("Varshith Pabbisetty")
2+
print("Varshith\"Pabbisetty")
3+
print("Varshith\Pabbisetty")
4+
5+
phrase = "Varshith Pabbisetty"
6+
print(phrase)
7+
print(phrase + " is cool")
8+
print(phrase.lower())
9+
print(phrase.upper())
10+
print(phrase.isupper())
11+
print(phrase.upper().isupper())
12+
print(phrase.capitalize())
13+
print(phrase.title())
14+
print(len(phrase))
15+
print(phrase[0])
16+
print(phrase.index("a"))
17+
print(phrase.index("Pabbisetty"))
18+
print(phrase.replace("Varshith", "Krishna Varshith"))

translator.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def translate(phrase):
2+
translation = ""
3+
for letter in phrase:
4+
if letter.lower() in "aeiou":
5+
if letter.isupper():
6+
translation = translation + "G"
7+
else:
8+
translation = translation + "g"
9+
else:
10+
translation = translation + letter
11+
return translation
12+
13+
print(translate(input("Enter a phrase: ")))

tryExcept.py

Whitespace-only changes.

tuples.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coordinates = (4, 5)
2+
print(coordinates[0])
3+
4+
coordinates = [(1, 2), (4, 5), (5, 6)]
5+
print(coordinates[0])
6+
print(coordinates[0][1])

variables&DataTypes.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
character_name = "Varshith"
2+
character_age = "23"
3+
4+
print("Hi, I am " + character_name)
5+
print("I am " + character_age + " years old")

whileLoop.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
num1 = 3
2+
3+
while num1 <= 10:
4+
print(num1)
5+
num1 += 1
6+

0 commit comments

Comments
 (0)